Home Java Beginners Java Read File Line by Line - Java Tutorial
Questions:Ask|Latest



Java Read File Line by Line - Java Tutorial
Posted on: June 4, 2007 By Deepak Kumar
In the section of Java Tutorial you will learn how to write java program to read file line by line. We will use the DataInputStream class to Read text File Line by Line.

Java Read File Line by Line - Java Tutorial

     

In the section of Java Tutorial you will learn how to write java program to read file line by line. We will use the DataInputStream class to Read text File Line by Line.

Class DataInputStream
A data input stream is use to read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream.

Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8. (For more information, see X/Open Company Ltd., "File System Safe UCS Transformation Format (FSS_UTF)", X/Open Preliminary Specification, Document Number: P316. This information also appears in ISO/IEC 10646, Annex P.) Note that in the following tables, the most significant bit appears in the far left-hand column.

BufferedReader

Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,

 BufferedReader in
   = new BufferedReader(new FileReader("foo.in"));
 
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.

Here is the code of java program to Read text File Line by Line:

import java.io.*;
class FileRead 
{
 public static void main(String args[])
  {

  try{
  // Open the file that is the first 
  // command line parameter
  FileInputStream fstream = new FileInputStream("textfile.txt");
  // Get the object of DataInputStream
  DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String strLine;

  //Read File Line By Line
  while ((strLine = br.readLine()) != null)   {
  // Print the content on the console
  System.out.println (strLine);
  }
  //Close the input stream
  in.close();
    }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
  }
  }
}

Download the code


Recommend the tutorial

Ask Questions?    Discuss: Java Read File Line by Line - Java Tutorial   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
houssam
April 14, 2011
shortly

FileReader inFile = new FileReader(filename); BufferedReader bufRead = new BufferedReader(inFile); while ((line = bufRead.readLine()) != null) { }
taniya tripathi
April 16, 2011
computer

diference between internet and intranet
mohan
May 26, 2011
appriciations

Thanks a lot to Rose India
lakshmanan
June 21, 2011
java

import java.io.*; class FileRead { public static void main(String args[]) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("textfile.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println (strLine); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } } in the above program why we need to use the BufferedReader Class? can u explain?
Caitlyn
June 24, 2011
I love you

I owe my first child to you. Without this I would've jumped off a five foot bridge.
James
June 24, 2011
How to Can I read previous line

Is there anyway to read previous line? for example I want to compare last line in file with certain value. how would I know that I've reached the last line?
Anonymous
June 26, 2011
Copy file to another with readline

String line = null; boolean firsttime = true; while ((line = input.readLine()) != null) { if (!firsttime) { contents.append(System.getProperty("line.separator")); firsttime = false; } mystringbuffer.append(line); }
Ashot
July 12, 2011
Why

DataInputStream in = new DataInputStream(fstream); Why do we need this? I tired code without it worked just as fine!
Bhuvi
June 10, 2013
read and write a file

Any one pls help me... I want 2 read a file and write the "lines which are all contains the word error" into other file...... How can i fetch the particular lines which has the word error???
aba duncan
August 24, 2011
java

Please at run time there is no command to open and read the file. Can u help me
AndReS
August 30, 2011
Thanks!

Hey, the code worked like a charm without a single change. Thanks a lot!
dag
September 7, 2011
missing Strem.close()

you open 3 strems and close only 1.. not good!
Anie
September 22, 2011
Not so important

Hey post some effective code not so good dude
yaya
September 28, 2011
Main Program

Hai... I have some problem with my project.can you help me? I didn't know why it cann't run.the problem in browse data. please help me. here the codes. package Yaya; import gov.nasa.worldwind.WorldWindow; import defaProject.FFrame; import gov.nasa.worldwind.geom.Position; import java.util.Vector; public class GUI extends javax.swing.JFrame { WorldWindow wwd; BacaFile bf; MainProgram mp; SatuanPosisi sp; Posisi position1, position2, position3, positionP; FFrame fFrame; private Vector<String[]> data1, data2, data3; /** Creates new form GUI */ public GUI(FFrame fFrame) { initComponents(); mp = new MainProgram(); this.fFrame = fFrame; Lat1.setText("-0.70417");Lon1.setText("119.85528"); Lat2.setText("-0.6");Lon2.setText("119.7"); Lat3.setText("1.19139");Lon3.setText("121.4225"); LatP.setText("-0.87639");LonP.setText("119.83861"); this.setTitle("Penentuan Ketinggian Air Laut"); } private GUI() { throw new UnsupportedOperationException("Not yet implemented"); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); Lat1 = new javax.swing.JTextField(); Lat2 = new javax.swing.JTextField(); Lat3 = new javax.swing.JTextField(); Lon1 = new javax.swing.JTextField(); Lon2 = new javax.swing.JTextField(); Lon3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); LatP = new javax.swing.JTextField(); LonP = new javax.swing.JTextField(); button2 = new javax.swing.JButton(); button1 = new javax.swing.JButton(); nameFile2 = new javax.swing.JLabel(); nameFile1 = new javax.swing.JLabel(); Run = new javax.swing.JButton(); button3 = new javax.swing.JButton(); nameFile3 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setResizable(false); jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153))); jLabel1.setText("Lokasi 1 :"); jLabel2.setText("Lokasi 2 :"); jLabel3.setText("Lokasi 3 :"); jLabel4.setText("Latitude"); jLabel5.setText("Longitude"); jLabel6.setText("Lokasi P :"); LonP.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { LonPActionPerformed(evt); } }); button2.setText("Browse"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseLokasi(evt); } }); button1.setText("Browse"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseLokasi(evt); } }); nameFile2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); nameFile2.setText(". . ."); nameFile2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102))); nameFile1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); nameFile1.setText(". . . "); nameFile1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102))); nameFile1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); Run.setText("Run"); Run.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Excecute(evt); } }); button3.setText("Browse"); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseLokasi(evt); } }); nameFile3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); nameFile3.setText(". . ."); nameFile3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102))); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(LatP, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(10, 10, 10) .addComponent(LonP)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Lat2) .addComponent(Lat1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE) .addComponent(Lat3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(10, 10, 10) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(Lon1) .addComponent(Lon3, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Lon2, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(jLabel4) .addGap(80, 80, 80) .addComponent(jLabel5) .addGap(39, 39, 39))) .addGap(27, 27, 27) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(button3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Run, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)) .addGap(24, 24, 24) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(nameFile3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nameFile2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nameFile1, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)) .addGap(31, 31, 31)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(button1) .addComponent(nameFile1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(15, 15, 15) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(button2) .addComponent(nameFile2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lat1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(Lon1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lon2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Lat2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Lat3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Lon3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3) .addComponent(button3) .addComponent(nameFile3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(14, 14, 14) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(LatP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(LonP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(Run))) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(20, 20, 20) .addComponent(jLabel6))) .addContainerGap(14, Short.MAX_VALUE)) ); button2.getAccessibleContext().setAccessibleParent(jPanel1); button1.getAccessibleContext().setAccessibleParent(jPanel1); Run.getAccessibleContext().setAccessibleParent(jPanel1); button3.getAccessibleContext().setAccessibleParent(jPanel1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void Excecute(java.awt.event.ActionEvent evt) { LeastSquare ls; positionP = sp.getData(3); double jarak1P = KonversiJarak.getJarak(position1.getLat(), positionP.getLat(), position1.getLon(), positionP.getLon()); double jarak2P = KonversiJarak.getJarak(position2.getLat(), positionP.getLat(), position2.getLon(), positionP.getLon()); double jarak3P = KonversiJarak.getJarak(position3.getLat(), positionP.getLat(), position3.getLon(), positionP.getLon()); double[] x = {jarak1P, jarak2P, jarak3P}; int numHari = data1.size(); int numJam = data1.elementAt(1).length; for (int i = 0; i < numHari; i++){ String[] temp1 = data1.get(i); String[] temp2 = data2.get(i); String[] temp3 = data3.get(i); for (int j = 0; j < numJam; i++){ double lev1 = Double.parseDouble(temp1[j]); double lev2 = Double.parseDouble(temp2[j]); double lev3 = Double.parseDouble(temp3[j]); double[] y = {lev1, lev2, lev3}; ls = new LeastSquare(x, y); double d = ls.getElevasi(0.0); } } } public void excecute() { mp.setDataP(Double.parseDouble(LatP.getText()),Double.parseDouble(LonP.getText())); mp.run(jPanel1); } private void browseLokasi(java.awt.event.ActionEvent evt) { bf = new BacaFile(); if (evt.getSource().equals(button1)){ data1 = bf.readElementByElement(); nameFile1.setText(bf.getNameFile()); position1 = sp.getData(1); fFrame.createIcon("stasiun", Position.fromDegrees(position1.getLat(), position1.getLon())); } else if (evt.getSource().equals(button2)){ data2 = bf.readElementByElement(); nameFile2.setText(bf.getNameFile()); position2 = sp.getData(2); fFrame.createIcon("stasiun", Position.fromDegrees(position2.getLat(), position2.getLon())); } else if (evt.getSource().equals(button3)){ data3 = bf.readElementByElement(); nameFile3.setText(bf.getNameFile()); position3 = sp.getData(3); fFrame.createIcon("stasiun", Position.fromDegrees(position3.getLat(), position3.getLon())); } } private void LonPActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GUI().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField Lat1; private javax.swing.JTextField Lat2; private javax.swing.JTextField Lat3; private javax.swing.JTextField LatP; private javax.swing.JTextField Lon1; private javax.swing.JTextField Lon2; private javax.swing.JTextField Lon3; private javax.swing.JTextField LonP; private javax.swing.JButton Run; private javax.swing.JButton button1; private javax.swing.JButton button2; private javax.swing.JButton button3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JLabel nameFile1; private javax.swing.JLabel nameFile2; private javax.swing.JLabel nameFile3; // End of variables declaration public Posisi getData(int index) { if (index==0) return Posisi.set(Double.parseDouble(LatP.getText()), Double.parseDouble(LonP.getText())); else if (index==1) return Posisi.set(Double.parseDouble(Lat1.getText()), Double.parseDouble(Lon1.getText())); else if (index==2) return Posisi.set(Double.parseDouble(Lat2.getText()), Double.parseDouble(Lon2.getText())); else if (index==3) return Posisi.set(Double.parseDouble(Lat3.getText()), Double.parseDouble(Lon3.getText())); return null; } }
Ben
February 21, 2013
This code

This was really helpful, thanks.
Neil
December 7, 2011
convaluted code isn't it?

Can't you just use: BufferedReader reader = new BufferedReader(new FileReader(filename)); to create the reader instead of all that guff?
Gaurav Chauhan
December 14, 2011
Awesome.

Thanks for this program. Its really knowledgeable.
Herock Hasan
December 14, 2011
FileReader

Excellent article and so much helpful. Hope another helpful content will also get from this website
frank
January 9, 2012
a question

will the above code, will be faster for reading a file whose size is greater than 200MB????
MANOJ SINGHAL
January 11, 2012
FOR JAVA TUTORIAL

Pls send me the complete java tutorial and updatation.
Crypt0s
January 14, 2012
File Reading

There is a much easier way to do this, and in one line: String line = ""; BufferedReader input = new BufferedReader(new FileReader("filename")); while ((line = input.readLine()) != null){ System.out.println(line); } //remember to close our streams or we run into issues! input.close();
Rachel
January 19, 2012
Thank You

Great site. Always been helpful.
vani
January 23, 2012
how to run this program

dear sir/madam, could you plz explain me the procedure to run this program Thanks vani
nikhil
February 9, 2012
location of text file

i am using ntebeans on windows..... so where do i place my text file so that the object reads it?????
Nikhil
February 9, 2012
error

the above code is giving a error of not recognizing the "in" symbol in netbeans.................please help
anilkumar
February 11, 2012
fileread

very easy program filereader
jAz
February 18, 2012
can you help me

can you help me making my thesis... music streaming via bluetooth. thankz...
tyrone A. taborete
February 27, 2012
computer programming

search text file
Jemmy Adams
March 5, 2012
Read text file

Sirs; Please, send step by step how can I read a text file, I am a mechanical engineer, not a programmer or IT. Thanks Jemmy
Vadim
March 22, 2012
xXVNjsHniYvn

Android system does not urasnetdnd PE format. so called windows exe files are in this format (PE stands for Portable Executable but it is not so portable after all!). likely Android executable frmat is ELF, a well-known widely used (among several systems) codes container .moreover, the code into windows executable files is for x86 processors (or for CLR, not JVM), and Android hardware for sure has no x86 processors and afaik no x86-opcode compatible processor too.so basically, it's nonsense converting an exe (specific format, specific system, specific machine code for specific processor, specific library bindings) into a file Android can read' (oh, as passive data you can transfer the exe to android as it is, but forget it can run it or even see that there's code inside! just data to it!) Was this answer helpful?
kok1n
April 5, 2012
awesome

thanks a lot, just what i needed!
pankaj
April 20, 2012
hi

thanks for this,it helped a lot.
Gabriel Alejandro Matossian
May 9, 2012
Thanks

I am very grateful, your article really helped me. Kind regards, Gabriel
Pratibha K
June 2, 2012
Deprecation error

for the line "while (( thisLine = br. readLine()) != null) { the dot after br is coming wrong in deprecation error. pls help me to solve this error.
Ferdinand
June 13, 2012
A little error

You also need to add "outFile.close();" after "in.close();" Otherwise the last chunk gets chopped off and lost.
Iman
June 15, 2012
Thank

Thank you for code
Henry
June 25, 2012
?

Where do you put the file???
Palle
June 26, 2012
FileRead

Hi Thank You very much ! I'm interested in Java programming. And I found Your example here. And I have downloaded it. I'm sure it will help me getting clever programming in Java. Yours sincerely Palle
iris potot
June 29, 2012
IT 16

give more examples!
kiper
July 5, 2012
nice tutorial

i tried it, no error :) i want to know, how to show the text file (*.txt) into form (textfield) and then import to mysql or another database
sakthi
July 9, 2012
java using applet

need java using applet login coding
Gadss
July 19, 2012
I got an error

hello, I try your code but I got this error: Error: textfile.txt (The system cannot find the file specified)
Bayan Al-Atrash
July 28, 2012
question

where must i save the file.txt??
Aishwarya Nathan
August 8, 2012


The code really really works :-)
Ä?ông
August 29, 2012
thanks

thanks so much
Mohd Shoaib
September 2, 2012
Computer Science(Java)

Really helpful!!!!!!!!!!!!!
Aldrin
September 11, 2012
String:

Hw to read a file frm a txt document & according to the no: of characters in the individual word we have to append the words in the document & display in the output screen.
pradip garala
September 21, 2012
thanks

Thanks for code...
pradip garala
October 3, 2012
thanks

thanks
nikhil
October 27, 2012
its easy way

/*FileInputStream fstream = new FileInputStream("textfile.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream);*/ //the above code can be avoided BufferedReader br = new BufferedReader(new FileReader("chits.txt"));
chief
November 13, 2012
NEED HELP URGENTLY

hi i have a file format like this 0274589654, 5 0245878968, 6 0278695455, -1 0245875258, .5 after reading from the file line by line. i want to read the first number into a variable and read the second number into another variable. need help urgently. thanks in advance for helping.
AnonymousOne
November 23, 2012
Alternative way

Try to be more concise... One can also try this: BufferedReader in = new BufferedReader(new FileReader("textfile.txt")); instead of using InputStreamReader, DataInputStream and FileInputStream. Hope it helps.
Swathi
December 4, 2012
Output

Hi, Can u plz tel me,How to run this program? show me in cmd prompt,how to run??? reply me
asdfghjkl20203
April 11, 2013
Another Way to New a BufferedReader

Instead of new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(new File(fileName))))); The following is more clear: new BufferedReader(new FileReader(filename));
tanveer islam
June 24, 2011
java file

how to create file
Jyothsna
May 31, 2013
Hi

Hey it will read the data whatever u entered ok.But It didn't interact with File.So I am thinking it is not corrrect>Please forgive if there is wrong in my discussion
Jyoths
May 31, 2013
hi

Sorry sorry I got thanq