|
|
Re: Help on read input file from Java
|
Posted: Mar 26, 2002 6:37 AM
|
|
To check how does it work, compile and run Test.java and don't forget to change the file name. Ideally, you should place your code in try-catch block. To keep it simple I didn't use try-catch here.
Thanks Kishori
///////////////////Test.java//////////
class Test {
public static void main ( String[] args ) throws Exception {
java.io.FileReader fr = new java.io.FileReader ( "c:\\kishori\\message.txt" ) ;
// You can read only in chars and bytes using FileReader
// To read a line at a time let us create a BufferedReader out of FileReader
java.io.BufferedReader br = new java.io.BufferedReader ( fr ) ;
String str = null ;
// Read the text on eline at a time and display it on console
while ( ( str = br.readLine()) != null ) {
System.out.println ( str ) ;
}
}
}
|
|