Here is the listing of Java programming examples on File Handling.
1. Java Examples on Files and Directories
File class represents the files and directory pathnames in an abstract manner. This class is used for creation of files and directories. This section contains Java programs on Creating a new file, copying one file to another file, creating a file in a specified directory, reading a file, deleting a file, displaying file properties and comparing paths of the two files.
Java Program to Create a New File
Java Program to Read a File
Java Program to Delete a File
Java Program to Copy a File
Java Program to Create a File in a Specified Directory
Java Program to Compare Paths of Two Files
Java Program to Display File Properties
2. Java Examples on Command Line Arguments & Passing Arguments
Command line argument is the argument passed to a program at the time when you run it. Java doesn’t pass method arguments by reference, it passes them by value. This section contains Java programs on passing command line arguments, printing second element of command line argument, performing addition of two numbers using command line arguments, finding factorial number by passing arguments, finding the average and sum of n numbers using command line arguments, check whether given number is odd or not by passing arguments.
Java Program to Print Second Element of Command Line Argument
Java Program to Pass Command Line Arguments
Java Program to Show Addition of Two Numbers Using Command Line Args
Java Program to Find Out the Factorial of Given Number by Passing Arguments
Java Program to Find the Average and Sum of the N Numbers Using Command Line Argument
Java Program to Find Out that the Given Number is Odd or Even by Passing Arguments
Java Program to Create Employee File Name Record that is taken from the Command-Line Argument
3. Java Examples on Byte Streams
A stream is an abstraction that either produces or consumes information. Byte streams are used for handling input and output of bytes. Byte streams are defined by using two class hierarchies they are InputStream and OutputStream. FileInputStream is used to reads from a file. Output stream that writes to a file. BufferedInputStream class is used to read information from stream. BufferedOutputStream Creates a new buffered output stream to write data to the specified output stream. Data input stream lets an application read primitive Java data types from an input stream. This section contains Java programs on creating a text files using FileOutputStream and BufferedOutputStream, reading a text files from FileInputStream and BufferedInputStream, compress files using DeflaterOutputStream, read the data using Data InputStream and display some values.
Java Program to Create a Text File Using FileOutputStream
Java Program to Create a Text File Using BufferedOutputStream
Java Program to Read Text File Using FileInputStream
Java Program to Read Text File Using BufferedInputStream
Java Program to Compress a File Using DeflaterOutputStream
Java Program to Use Data Input Stream
Java Program to Read the Data Using Data InputStream and Display some of Corresponding Values
4. Java Examples on Character Streams
Character streams are used for handling input and output of characters. Character streams are more efficient than byte streams. Character streams are defined by using two class hierarchies they are Reader and Writer. BufferedReader class is used to read the text from a character-based input stream. FileReader is used for reading streams of characters. This section contains Java programs on exploring streams types, converting inputstream into reader, reading text file using FileReader, converting outputstream, using Buffered Reader to read characters from the console.
Java Program to Exploring Types of Streams
Java Program to Convert InputStream into Reader
Java Program to Read Text File Using FileReader
Java Program to Convert OutputStream into Java Program
Java Program to Use a Buffered Reader to Read Characters from the Console
5. Java Examples on ObjectOutputStream
ObjectOutputStream is a type of Byte streams, Byte streams are used for handling input and output of bytes. ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. The objects can be read using an ObjectInputStream. ObjectInputStream deserializes data and objects previously written using an ObjectInputStream. InflaterInputStream creates a new input stream with a default decompressor and buffer size. This section contains Java programs on storing a file using ObjectOutputStream. uncompress a file using InflaterInputStream, read objects from a file using ObjectInputStream.
Java Program to Store Objects to a File Using ObjectOutputStream
Java Program to Uncompress a File Using InflaterInputStream
Java Program to Read Objects from a File Using ObjectInputStream
6. Java Examples on Serialization and Deserialized
Serialization is a mechanism of converting the state of an object into a byte stream. The reverse process of creating object from sequence of bytes is called deserialization. Transient keyword is used in serialization. If we declare any data member as transient, it will not be serialized. Externalization serves the purpose of custom Serialization, where we can decide what to store in stream. This section contains Java programs on serialization and deserialized use, use of transient keyword, use of externalizable interface, program to display use of static and instance method in serialized and deserialized.
Java Program to Use of Serialization and Deserialized
Java Program to Use of Transient KeyWord
Java Program to Use of Externalizable Interface
Java Program to Show What is the Use of Static Method and Instance Method in a Serialized
Java Program to Show What is the Use of Static Method and Instance Method in a Deserialized
7. Java Examples on Read and Accept Data Types from Keyboard
The Java programs in this section on reading single and multiple integers from keyboard, accepting and displaying a character from the keyboard, programs to accept strings, integers and float numbers from keyboard and handling files with mixed data type.
Java Program to Read Sigle Integer From KeyBoard
Java Program to Read Multiple Integer From KeyBoard
Java Program to Accept and Display a Character from the Keyboard
Java Program to Accept a Name (string) from the KeyBoard
Java Program to Accept an Integer from KeyBoard
Java Program to Accept a Float Number
Java Program to Handle Files with Mixed Data Type
8. Java Examples on Operations like Creating, Counting & Conversion of Files
This section contains Java programs on file operations like creating, counting and conversion of contents of a file like converting content of file into uppercase or lowercase, counting number of characters in a file, counting number of lines, blank lines and comments in a given file, reading a .doc file and converting .doc file to .txt file.
Java Program to Convert the Content of File to UpperCase
Java Program to Count No of Lines, Blank Lines, Comments in a Given Program
Java Program to Convert the Content of File to LowerCase
Java Program to Create and Count Number of Characters in a File
Java Program to Create a Text File Using File Java Program forr
Java Program to Java Program for to a File
Java Program to Read xxx.doc File and Convert Its into xxx.txt File
9. Java Examples on Files Operations Replacing, Updating & Reversing the Contents of a Files
This section contains Java programs on file operations like replacing first letter of every word in a file will replace with capital letter, reverse the contents of a file and print it, update the details of employees using files.
Java Program to Replace First Letter of Every Word with Capital Letter
Java Program to Reverse the Contents of a File and Print it
Java Program to Update Details of Employee Using Files
10. Java Examples on Files Modifications
This section contains Java programs on modifications of files like renaming a file, getting the file size in bytes, change the last modification time of a file, get the last modification date of a file, create a temporary files, appends a string in an existing file, checks whether file exists or not, make a file in only read mode and copying one file to another file.
Java Program to Renaming a File
Java Program to Get a File’s Size in Bytes
Java Program to Change the Last modification Time of a File
Java Program to Create a Temporary File
Java Program to Append a String in an Existing File
Java Program to Copy One File into Another File
Java Program to Check a File Exist or Not
Java Program to Make a File Read-Only
Java Program to Get Last Modification Date of a File
11. Java Examples on Static Import & Type Casting
Static import allows to access the static members of a class without the class qualification. Type casting is used to convert an object or variable of one type into another. This section contains Java programs on demonstrating the type casting, showing the use of static import, and special program to display its own source code as its output.
Java Program to Show the Use of Static Import
Java Program to Demonstrate Type Casting
Java Program to Display its Own Source Code as its Output
12. Java Examples on Contents of a Files
This section contains Java programs on merging all lines in a both files and store them in a new file, program to collect statistics of source file like total number of lines, blank lines and number of lines ending with semicolon.
Java Program to Join Lines of Two given Files and Store them in a New file
Java Program to Collect Statistics of a Source File like Total Lines, Total no. of Blank Lines, Total no. of Lines Ending with Semicolon