Processing large file in Java


Processing large file in Java

In this tutorial we are going to discuss about processing large files in Java.

In this tutorial we are going to discuss about processing large files in Java.

Processing Large Files in Java with example code

Java programming language is one of the most popular object oriented programming language with extensive support for file processing. Java API allows you to create file, update file, read file, move file, copy files, delete file and perform various kinds of operations. You can work with both text and files in Java using appropriate APIs.

In this tutorial we are going to discuss about ways to process different file types in Java. During application development developers works with various file types in Java. Each file type comes with different ways of reading and working with the various file formats. The way of working with each file is different for example method of working with csv file is different from reading a binary file.

If you have text file of very big size then best solution is to read the file line by line with the help of BufferedReader class in Java. This class provides the readLine() method which reads file one line at at time. This is the most efficient method of reading a text file without any memory issue in Java.

In this page we are providing code and example link of reading for reading and processing large large text file using Java code.

Processing Large file in Java

Java comes with many libraries and APIs to work with specific file type. Following table describes file types and API used in Java for working with these files.

Sr. No. File type API/Library Used
1. CSV File BufferedReader, Read file line by line
2. Zip file is used for reading Zip file in Java.
3. Word File Apache POI library is used to read word file in Java
4. PDF File org.apache.pdfbox is used to read PDF file in Java
5. Excel File Apache POI library is used to read Excel file in Java
6. PPT File Apache POI library is used to read PPT file in Java
7. PST File java-libpst is used to read PST file in Java.
8. MBOX file can be used.
9. Binary Files  java.nio.file package classes can be use to read Binary files in Java.
10. Image Files java.awt.Image can be used to read image file.
11. Video Files Classes in the package or any other library can be used.
12. Stream Reader The class can be used.
13. Reading and Writing to Text file BufferedReader class can be used.
14. Properties files(.properties) The class java.util.Properties is used for this purpose.
15. BMP Files ImageIO class can be used top read bmp file in Java.

Read big text file in Java

In this example code we are going to to read a big text file with a size of 3GB with Java code line by line. Big file can be ready only through line by line. If you try to read a big file in memory then it will crash and throw out of memory exception. Here is an example of reading a big text file in Java:

BufferedReader br = new BufferedReader(new InputStreamReader(in));

The BufferedReader class is used to read a Big File line by line in Java. Check it at Java Read File Line by Line.

In this tutorial we have discussed Java technologies and various libraries used to work with various file types. Here are the best tutorials to work with large files in Java:

Introduction to Java

Java tutorials for complete beginners in Java

  1. How to Get Started with Java?
  2. New to programming
  3. What is Java?
  4. Java as an Internet Language 
  5. Java as general purpose language

Tutorials for Mastering Java

Here are the tutorials for programming having experience in Core Java.

  1. Master Java Tutorials (TOC) 
  2. Java as a programming language 
  3. Java as an Object Oriented Language