Click here to Skip to main content
11,926,429 members (60,405 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java file
how can i read textfile line by line when i have the absolute path of the file using java?
Posted 5-Dec-12 4:34am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hope Helped !!

class FileRead 
 public static void main(String args[])
  // 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
    }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
ridoy 5-Dec-12 11:41am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100