Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in a text File 1

Status
Not open for further replies.

Edge118

Programmer
Jun 15, 2004
104
US
Hi,

I got the following code off of the sun website, and I was wondering if anyone would be able to tell me how to go through each line of the file one by one and store store each line in a string so I can manipulate it. The sun site wasn't very helpful. Thanks for your help.

Code:
import java.io.*;

public class Program1
{
  public static void main (String[] args) throws IOException
  {
    File inputFile = new File("Censure.txt");
    FileReader in = new FileReader(inputFile);

  }
}

"Pin me. Perl me."

Regards,

Chris
 
I'm pretty new to Java myself, but here's what I do; see if it helps:
Code:
BufferedReader input = new BufferedReader (new FileReader (inF)); 
//where inF is a file name string
while ((line = input.readLine()) != null) {
      //now "line" is a string representation of a line from inF
      //do what you want with it
}
input.close ();

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top