Tutorial

Java IO Tutorial

Published on August 3, 2022
Default avatar

By Pankaj

Java IO Tutorial

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Java provides several classes in java.io package to work with text, stream data, and file system. I have provided several examples on Java Files and Java IO recently. This post is an index of all Java IO articles.

Java IO

Java IO

  1. How to Create New File in Java In this post, you will learn how to create a new file in java program and use of “file.separator” system property to make our program platform independent.
  2. How to delete a File in Java This post explains how to delete a file or empty directory in java, notice that delete doesn’t throw any exception even if directory is not empty and not deleted.
  3. Java File separator, separatorChar, pathSeparator, pathSeparatorChar Explained with Example Learn about the four separator static variables of File class.
  4. How to delete non empty directory in Java A recursive program to delete non-empty directories in java.
  5. Rename file or Move file in Java Learn how easily you can rename a file or move it into other directory in java.
  6. File Size in Java Learn how to get the file size in java program.
  7. Get File Extension in Java Java File doesn’t have any method to get file extension, a utility program showing how to get file extension in java.
  8. Check File Exists in Java Learn how to check if file exists or not in java.
  9. How to check if File is Directory? Learn how to find out if the file is actually a directory.
  10. File Last Modified Date in Java Find out how to get last modified date of a file in java.
  11. Java FileNameFilter Example Learn how to use FileNameFilter to list files with specific extension in java.
  12. Java File Path, Absolute Path and Canonical Path Explained Learn the difference between different types of file paths in java.
  13. Java File Permissions Learn how to get the file permissions for the application user in java program and how to set permissions using File class.
  14. How to set File Permissions in Java Easily using Java 7 PosixFilePermission Learn the pitfalls of using File class to set permissions and why Java 7 PosixFilePermission are the best way to set file permissions in java.
  15. Copy File in Java Learn how to copy file using Stream, FileChannel, Apache Commons IO and Java 7 Files class and which is the best way to copy file in java.
  16. Open File in Java Learn how to open a file in associated application using java.awt.Desktop class.
  17. Read File in Java Learn how to read file using FileReader, BufferedReader, Scanner class and Java 7 Files class and find out how to get encoding support and best way to read file in java.
  18. Java File Scanner Example Learn how to use Scanner class to read complete file, parse a file based on regular expression and tokens.
  19. Read a File to String in Java Learn how to read the complete file into a String in java.
  20. Java read file line by line Learn how to read file line by line in java, good for working with large files in java.
  21. Write a File in Java Learn how to write a file using FileWriter, BufferedWriter, Java 7 Files class and FileOutputStream and which one to choose based on your project requirements.
  22. Append Text to File in Java Learn how to append data to existing file in java.
  23. Java InputStream to File Example Learn how to convert InputStream to file in java using OutputStream.
  24. Java Random Access File An example showing usage of Java RandomAccessFile to read and write data to specific index in file.
  25. Download File from URL Learn how to download a file from URL in java program.
  26. How to write Object to File in Java Learn how to save object to a file in java using Serialization.
  27. How to read Object from File in Java Learn how to create Object from file in java using Deserialization.
  28. How to Compile and Run a Java Program in another Java program A misc program showing how can we compile and run java program from another java program.
  29. Java Property File and Property XML Learn how to read and write property file and property xml files in java.
  30. Compress File or Directory using Java ZIP In this article, you will learn how to compress a file in ZIP format, the example shows how to recursively compress a directory to ZIP format.
  31. Java Unzip File Example In this article, you will learn how to decompress a zip archive.
  32. Java GZIP Example In this article, you will learn how to compress a file in GZIP format and then how to decompress it in Java.
  33. Java Temp File Java provides API to create temporary files to be used by the program, the file names are random so it’s hard to hack it. Learn how to create temp files in Java and read/write data into them.

Make sure to share it with others and bookmark it for future use.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Pankaj

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
August 27, 2019

hi I have seen almost all ur post ,I need something like aligning the data while writing into the file. like (name age dept)–>(a,00,a),(aa,0,sss) so on .the thing is I need to align like it prints into file in proper tab spaces .

- madesh

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel