The Java I/O means Java Input/Output. It is provided by the java.io package. This package has an InputStream and OutputStream. Java InputStream is defined for reading the stream, byte stream and array of byte stream.
Java I/0 Examples
- What is Java I/O?
The Java I/O means Java Input/Output. It is provided by the java.io package. This package has an InputStream and OutputStream. Java InputStream is defined for reading the stream, byte stream and array of byte stream.
- Classes and Interfaces of the I/O Streams
The following listing of classes provided by the java.io package shown in the given table.
- Reading Text from
the Standard Input
Java provides the standard I/O facilities for reading text through either from the file or from the keyboard on command line. This program illustrates how to use standard input to read the user input.
- Working With
the Files
The File class deals with the machine dependent files in a machine-independent manner i.e. it is easier to write platform-independent code that examines and manipulates files using the File class. This class is available in the java.lang package.
- Create a File
- Constructing a File Name path
- Read the File
- Write to a File
- Appending to a File
- Getting the Size of a File
- Count lines of a particular file
- Renaming a File or Directory
- Copying a File to Another File
- Copying Multiple Files
- Moving a File or Directory to Another Directory
- Deleting a File or Directory
- Change a File timestamp
- Create a Temp File
- Delete a Temp File
- Getting an absolute path
and Parents of a Filename
Video: Learn Java I/O packages
- Working with a Directory
In the section, you will learn how a directory is created. Apart from this, you will also be aware from some manipulations that are performed
on a directory.
- Filter I/O Streams
Like I/O streams, Filter streams are also used to manipulate the data reading from an underlying stream.. Apart from this, it allows the user to make a chain using multiple input stream so that, the operations that are to be applied on this chain, may create a combine effects on several filters. - Overview of I/O Data Streams
Data streams are filtered streams that perform binary I/O operation on primitive data type values ( boolean, char, byte, short, int, long, etc.) as well as on String values. If you need to work with data that is not represented as bytes or characters then you can use Data Streams.
- Using a Random Access
File
n this section, you will learn about the Random Access File class provided by java. io package. This is a class that allows you to read and write arbitrary bytes, text, and primitive Java data types from or to any specified location in a file.
- Converting
a Filename Path to a URL
In this section, you will learn, how a Filename path is converted to a URL and vice versa . URL stands for Uniform Resource Locator.
- Making Tokens of a Java Source Code
In Java, The StreamTokenizer class is used for simple parsing of a Java source file into tokens. This class takes an input stream, breaks up the ASCII text in a file and parses it into "tokens". It allows the tokens to be read one at a time.
- Introduction to Encoding
Java programs use Unicode text internally. It supports standard UTF-8 when reading and writing strings through the InputStreamReader and the OutputStreamWriter. - Reading UTF-8 Encoded Data
- Writing UTF-8 Encoded Data
- Reading ISO Latin-1 Encoded Data
- Writing ISO
Latin-1 Encoded Data
- Serializing
an Object
Serialization is the process of saving an object in a storage medium (such as a file, or a memory buffer) or to transmit it over a network connection in binary form.
- Deserializing an
Object
The opposite operation of the serialization is called deserialization i.e. to extracting the data from a series of bytes is s known as deserialization
- Delete file or Directory
In this example we are discussing the deletion of a file or a directory by using a java program. We pass the file name or the directory name to which we want to delete.
- Downloading and Viewing html source of a page i.e. running on the
server
This section illustrates you the procedure of viewing complete html code of a page i.e. running on the server.
- URL file Download and Save in the Local Directory
This Program file download from URL and save this Url File in the specified directory. This program specifies the directory path where the files to be stored as first command line argument and second command line arguments specifies URL File to be stored.
- Create XML file from flat file and data insert into database
In this section, we have developed an application to create xml file from flat file and data insert into database in Java.
-
Miscellaneous
- Delete File Example
In this section, you will learn how to delete a file.
- Buffer Reader
In this section you will learn how to read line by line data from a file using BufferedReader.
- File Input Stream
Java has Two types of streams- Byte & Characters.
- File Output Stream
As we discussed earlier, java has two kinds of streams- Byte & Characters.
- Last Modified Date
This section contains the detail about how to get the last modification date of a file.
- Java File Handling
For file handling in java, the package known as java.io is available.
- File Compare
In this section, we will discuss how to compare pathname of two file for the equality of their path.
- Read File Buffered Writer Example
In this section, you will learn how to write to a file using BufferedWriter.
- Copy File Example
In this section, you will learn how to copy content of one file into another file.
-
File Handling In Java
In this section we will discussed about How files can be handled in Java. - Java I/O Byte Streams
In this section we will discussed the I/O Byte Streams. -
Java I/O Character Streams
In this section we will discuss the I/O Character Streams. -
Java I/O Buffered Streams
In this section we will discuss the I/O Buffered Streams. -
Java I/O Data Streams
In this tutorial we will discuss the Java I/O Data Streams. -
Java I/O Object Streams
In this section we will discuss the Java IO Object Streams. - Scanning and Formatting in Java
In this we will discuss about the Java I/O Scanning and Formatting. - Java I/O From the Command Line
In this section we will learn about the I/O from the command line in Java. - Java IO Path
In this section we will discuss about the Java IO Path. - Java Path Class
In this section we will discuss all the aspect of Path class of Java. - Java IO InputStream Example
In this section we will discuss about the InputStream in Java. - Java Byte Streams Example
In this section we will discuss how to read one byte at a time from the input stream. - Java IO SequenceInputStream Example
In this tutorial we will learn about the SequenceInputStream class. - Java FileInputStream
In this section we will discuss about the Java IO FileInputStream. - Java PipedInputStream
In this example we will discuss about the Java PipedInputStream. - Java ObjectInputStream
In this example we will discuss about the Java class ObjectInputStream. - Java FilterInputStream Example
In this tutorial we will discuss about the FilterInputStream class in Java. - Java IO OutputStream
In this section we will read about the OutputStream class of java.io package. - Java FileOutputStream Example
In this section we will discuss about the Java IO FileOutputStream. - Java ByteArrayOutputStream Example
In this section we will discuss about the Java IO Byte Streams ByteArrayOutputStream class. - Java PipedOutputStream
In this tutorial we will discuss about the Java PipedOutputStream. - Java PipedInputStream and PipedOutputStream
In this section we will discuss about the PipedInputStream and PipedOutputStream in Java. - Java ObjectOutputStream
In this tutorial we will discuss about the Java class ObjectOutputStream. - Java ObjectOutputStream ObjectInputStream
In this section we will discuss about the ObjectOutputStream and ObjectInputStream in Java. - Java FilterOutputStream Example
In this section we will discuss about the FilterOutputStream class in Java. - Java IO Reader
In this section we will discuss about the Reader class in Java. - Java IO FileReader
In this tutorial we will learn about the FileReader class in Java. - Java IO BufferedReader
In this section we will discuss about the BufferedReader class in Java. - Java IO CharArrayReader
In this tutorial we will learn about the CharArrayReader class in Java. - Java IO FilterReader
In this section we will learn about the FilterReader class in Java. - Java IO StringReader
In this section we will discuss about the StringReader class in Java. - Java IO InputStreamReader
In this section we will discuss about the InputStreamReader in Java. - Java IO PipedReader
In this section we will discuss about the PipedReader in Java. - Java IO LineNumberReader
In this tutorial we will learn about the LineNumberReader in Java. - Java PushbackReader
In this section we will discuss about the PushbackReader class in Java. - Java IO Writer
In this section we will discuss about the Writer class in Java. - Java IO BufferedWriter
In this section we will discuss about the BufferedWriter class in Java. - Java IO CharArrayWriter
In this tutorial we will learn about the CharArrayWriter in Java. - Java IO FilterWriter
In this example we will discuss about the FilterWriter in Java. - Java IO OutputStreamWriter
In this section we will learn about the Java OutputStreamWriter. - Java IO PipedWriter
In this tutorial we will learn about the PipedWriter in Java. - Java IO PrintWriter
In this tutorial we will learn about the the PrintWriter class in Java. - Java IO StringWriter
In this section we will discussed about the StringWriter in Java. - Command Line Standard Input In Java
In this section we will discuss about the Java IO Standard Input through Command Line. - Command Line Standard Output In Java
In this section we will discuss about the Command Line Java IO Standard Output. - Command Line Standard Error In Java
In this section we will discuss about the Command Line Java IO Standard Error. - How To Read String From Command Line In Java
In this section we will discuss about how string can be read through the command line. - How To Read Integer From Command Line In Java
In this section we will discuss about how an integer can be read through the command line. - Java IO File
In this section we will discuss about the File class in Java. - How To Create a New File
In this section we will discuss about how to create a new file in Java. - How To Read File In Java
In this section we will discuss about about how data of a file can be read in Java. - Java Construct File Path
In this section we will discuss about how to construct file path in Java.