How to Read a Tab Delimited File in Java

Written by lysis
  • Share
  • Tweet
  • Share
  • Email

Reading tab delimited files is an essential way to read basic output from Java. Some databases export data in tab or comma delimited format, so importing that data in Java is a way to display the results of a database to an application that is unable to query the tables directly. Importing and reading tab delimited files only takes a few lines of code in the application development with Java.

Skill level:


  1. 1

    Import the necessary class libraries. Reading files requires the IO class library that is not automatically included. The following syntax includes libraries for reading tab delimited files: import; import;

  2. 2

    Set the variables to read the files. File buffers are used to read file data into memory for faster processing. The following text reads a file that is tab delimited to parse the information. BufferedReader readbuffer = new BufferedReader(new FileReader("myFile.txt")); String strRead;

  3. 3

    Read the delimited information. The following loop separates the tab delimited information into an array variable and prints it to the console. The "\t" notation is the switch that indicates a tab delimeter: while ((strRead=readbuffer.readLine())!=null){ String splitarray[] = strRead.split("\t"); String firstentry = splitarray[0]; String secondentry = splitarray[1]; System.out.println(firstentry + " " + secondentry); }

  4. 4

    Close the stream to free memory resources on the host computer: readbuffer.close();

Don't Miss


  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.