Processing large file in Java

Ads
 
Tutorials   
How to convert a stack trace to a string? Example code of reading file line by line in Java with Apache Commons IO library How to store unique values in Java using Set? java.nio ShortBuffer Example How to use Java Path class? Java NIO Package Tutorial How to limit object creation in Java? Java 11 String lines function example to split it in lines Top upcoming features of JDK 11 Java/JDK 11 Tutorial How to install JDK 10 in Ubuntu 18.04? Install JDK 10 on Windows Java 10 features Processing large file in Java Learning Java for non programmers Why You Should Learn Java in 2018? Installing JDK 9 on Windows 10 How to convert binary to decimal in Java? How to add two numbers in Java? What is Applet in Java with Example? What is nested class in Java with Example? Exception handling in Java Programming Examples What is Constructor Overloading in Java? How to display image in Swing? What is Java programming used for? How to create custom exception in Java? How to set CLASSPATH in Java? What is Multithreading in Java? IO Streams in Java with Examples How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer? Learn Java Programming for beginners 5 Reasons Java is Still a Great Language to Boost Your Career Prospect as a Programmer

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 java.util.zip.ZipFile 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.
https://github.com/rjohnsondev/java-libpst
8. MBOX file MBoxAdapter.java 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 javax.media package or any other library can be used.
12. Stream Reader The  java.util.stream.Stream 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

Ads

Ads