Java IO is an API that comes with Java which is targeted at reading and writing data (input and output). Most applications need to process some input and produce some output based on that input. For instance, read data from a file or over network, and write to a file or write a response back over the network.
The Java IO API is located in the Java IO package (java.io).
Use these tutorials for some nice concepts aroung Java IO APIs.
Related Tags
Tutorials
Java IO is a collection of APIs targeted at reading and writing data from various sources to several targets. For example, we can read data from a file or over a network, write to a file or write a response back over the network. This page categorizes the various IO-related common tasks into a logical grouping so …
Learn to find a file by name in a given directory and its sub-directories in Java and search up to a configured depth of sub-directories with examples.
Learn to copy or pipe the byte[] data from InputStream to OutputStream for small streams and also for large streams over 2 GB.
Learn to convert a Reader to InputStream and also convert InputStream to Reader in this short Java IO tutorial.
Learn to create a new single directory or nested directory along with parent directories in a specified path using Java IO and NIO classes.
Learn to count all the lines in file with the efficient solutions like Stream of lines, List and LineNumberReader classes.
Learn to a few performance-proven methods to check if a given directory is empty or not using the Java NIO Files and DirectoryStream classes.
Learn to get the creation date and time of a file in Java using Java NIO Files class in different time units since epoch and to Instant.
Learn to create, detect and find targets of the symbolic links (also known as symlinks or soft links) using examples in Java.
Learn to make the file empty by deleting all the content in it. This makes the file size zero without deleting the file itself.
Learn to write the given byte[] into a file using different solutions. We will be using the Java NIO, Commons IO and Guava APIs that provide simple APIs for this usecase.
Learn to read all the lines from a file into ArrayList using Java IO and NIO APIs, Stream API, Commons IO and Guava classes.
Learn to read a specific line from a text file in Java. We will learn to write the solution for small files as well as large files as well.
Learn to read all lines from a large file (size in GB) in Java and avoid any performance pitfalls such as very high usage of memory or even OutOfMemoryError if the File is large enough.
Learn to delete a specified file or directory in Java. Note that different methods behave differently for deleting non-empty directories.
Learn to rename a file or directory at a specified path or move to a new directory in Java. We will learn to use the classes from Standard IO, New IO, Guava and Commons IO.
Learn the difference between path, absolute and canonical paths. Also, learn to get the path of a file in Java using standard IO and New IO classes.
Learn to get the size of a file or a directory in Java using IO classes File, Files and Common IO’s FileUtils class.
The Java FileWriter class is for writing the text to the character-based files using a default buffer size. It uses character encoding default to the platform, if not provided otherwise. FileWriter is usually wrapped by higher-level Writer types, such as BufferedWriter or PrintWriter. FileWriter provides better performance and higher-level, more …
The Java InputStreamReader class is often used to read characters from files (or network connections) where the bytes represents text. In this Java tutorial, we will learn about InputStreamReader class, its creation and initialization, and its methods which help in reading the data from the source. 1. InputStreamReader class It …
Java StringReader represents a character stream whose source is a string. Use it to pass a string to a method that accepts a Reader Type.
Java FileReader class can be used to read data (stream of characters) from files. In this tutorial, we will learn about FileReader class, its constructors, methods and usages with the help of examples. 1. Introduction The FileReader class is: 2. Creating FileReader To use the FileReader in the application, we …
Learn to read a file from classpath in Java. The file can be present at root of class path location or in any relative sub-directory.
Learn to append the data to a file in Java using Standard IO’s BufferedWritter, PrintWriter, FileOutputStream and NIO Files classes.
Learn to write text and binary data into files using Java Writer, FileChannel, ByteBuffer, Files.write() and writeString() methods in Java 8 and Java 11.
Learn to resolve the InputMismatchException by reading the typesafe user inputs from the console in any interactive java application.
Learn to read a text file into String using Files.readAllBytes(), Files.lines() and BufferedReader classes in various ways.
Learn to convert OutputStream to InputStream in Java using ByteArrayInputStream and Java NIO Files Channel API.
Java examples of unzipping and extracting the zip file using java.util.zip package and apache commons compress module.
To find the current working directory for any Java application, we can use System.getProperty(“user.dir”) or Paths.get().toAbsolutePath().
Java examples of reading a file from the resources folder from a jar file, war file, spring application or the development environment.
Learn to create password-protected zip files using a very useful library Zip4j that uses completely Java code without any native code.
Learn to copy a directory into a new location in Java. Learn to apply FileFilter to include or exclude subdirectories and specific files.
Learn to make a file read-only in Java. A read-only file can be opened for reading, but we cannot modify or delete the file contents.
Copying a file from one place to another in Java is a common task. Learn to copy files using Java NIO, Commons-IO and Guava APIs.
Learn to use the Java FilenameFilter to traverse a directory and search all files with names matching a specified pattern.
Learn to create BufferedWriter with default, configure custom internal buffer sizes and write characters data into a file using it.
Learn to create and operate the BufferedReader instance, set default buffer size and read from a file and system console with examples.
Learn to create a new file using different techniques including NIO Files and Path, IO File, File OutputStream, and open-source libraries.
Learn how Java IO operations are mapped at the machine level; and what all things the hardware does all the time when application is running.
Learn how to delete a temporary file in Java. We will see examples to use File.deleteOnExit() and File.delete() methods.
Learn to create a temp file and directory in Java using the legacy and NIO classes. Also, learn to delete temp files or temp directories on JVM shutdown.
Learn to create a temporary file and write to it in Java. We will use the code sample used for creating a temporary file example.
Learn to check if a file exists or a directory exists in given path in Java. Also check is file is readable, writable or executable.
Java example to convert String to InputStream using ByteArrayInputStream and IOUtils classes. Writing String to InputSteam is a frequent job .
Learn reading data from files into a byte array in Java using NIO Files, FileInputStream, Commons IO FileUtils, and Guava ByteStreams classes.
Learn reading and writing UTF-8 content into a file using BufferedReader and BufferedWriter in Java.
For reading a file line by line, the LineNumberReader class could be used that allows to keep track of which line we are currently processing.
Learn to read property file in java using Properties.load() method. Then we will use Properties.setProperty() method to write a new property into file,
Learn to read the user input from the console in Java and write to the console using Console, BufferedReader and Scanner with examples.