COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button
JAVA EXAMPLES READ A FILE
Java Examples - Read a file
Problem Description:
How to read a file?
Solution:
This example shows how to read a file using readLine method of BufferedReader class.
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader
(new FileReader("c:\\filename"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
System.out.println(str);
}
catch (IOException e) {
}
}
}
}
Result:
The above code sample will produce the following result.
aString
No comments:
Post a Comment