Files Tutorials


Working with files in Java can be surprisingly easy when you have examples to work with. This page attempts to provide those examples.
  1. How do I write a String to a File?
  2. How do I read a String from a File?
  3. How do I write a JavaBean to an XML file using JOX?
  4. How do I read a JavaBean from an XML file using JOX?
  5. How do I write a JavaBean to an XML file using XMLEncoder?
  6. How do I read a JavaBean from an XML file using XMLDecoder?
  7. How do I write to an Excel file using POI?
  8. How do I read from an Excel file using POI?
  9. How do I write to a PDF file using iText?
  10. How do I read a properties file?
  11. How do I write a properties file?
  12. How do I read properties from an XML file?
  13. How do I write properties to an XML file?
  14. How do I read a String from a File line-by-line?
  15. How do I read a properties file with a Resource Bundle?
  16. How do I display the contents of a zip file?
  17. How do I unzip the contents of a zip file?
  18. How can I create a zip file from a set of files?
  19. How can I create an uncompressed zip file from a set of files?
  20. What's the difference between a file's path, absolute path, and canonical path?
  21. How do I get a URL or URI to a file?
  22. How do I display the contents of a directory?
  23. How do I use a FileFilter to display only the directories within a directory?
  24. How do I use a FilenameFilter to display a subset of files in a directory?
  25. How do I recursively display all files and directories in a directory?
  26. How do I zip a directory and all its contents?
  27. How do I deflate and inflate a file?
  28. How do I compress and uncompress a gzip file?
  29. How do I write the contents of a file to standard output?
  30. How do I write an object to a file and read it back?
  31. How do I redirect standard output to a file?
  32. How do I redirect standard error to a file?
  33. How do I generate an MD5 digest for a file?
  34. How do I encrypt and decrypt files using DES?
  35. How do I use a SequenceInputStream to connect several FileInputStreams?
  36. How do I alphabetically sort the lines of a file?
  37. How do I write a String to a File using Commons IO?
  38. How do I read a String from a File using Commons IO?
  39. How do I get a List of the lines in a File using Commons IO?
  40. How do I get a List of the lines in a File using Commons IO and alphabetize them?
  41. How do I determine the size of a directory?
  42. How do I display a cleanly formatted file size?
  43. How do I perform a touch on a file?
  44. How do I get all files in a directory including subdirectories using Commons IO?
  45. How do I get all files with certain extensions in a directory including subdirectories?
  46. How do I determine the free space on a drive?
  47. What's a quick way to tell if the contents of two files are identical or not?
  48. How do I copy a file?
  49. How do I copy a file to a directory?
  50. How do I move a file?
  51. How do I move a file to a directory?
  52. How do I filter files based on their last-modified dates?
  53. How do I get the directories in a directory using a filter?
  54. How do I select files to a particular depth in a directory?
  55. How do I get the files in a directory using a filter?
  56. How do I get the hidden or visible files in a directory using a filter?
  57. How do I sort an array of files according to their last modified dates?
  58. How do I sort an array of files according to their names?
  59. How do I get an array of files based on a file prefix?
  60. How do I get an array of files based on a regular expression?
  61. How do I sort an array of files according to their sizes?
  62. How do I get an array of files based on a file suffix?