Ak Java Freak
Posts : 23 Join date : 2009-02-07
| Subject: java print the content of text file in the console Tue Feb 10, 2009 3:39 am | |
| - Code:
-
import java.io.*; public class textreader {
public static void main(String args[]) throws IOException { try { //open the file FileInputStream fis = new FileInputStream("C:\\file.txt");
//get the object from datainputstream DataInputStream dis = new DataInputStream(fis); BufferedReader br = new BufferedReader(new InputStreamReader(dis)); String stringline;
//read file line by line while((stringline = br.readLine()) != null) { //print the content of the file in the console System.out.println(stringline); } //close the datainputstream dis.close(); } catch(Exception e) { e.printStackTrace(); } }
}
| |
|