Google

Monday, October 5, 2009

FileInputStream : how to read text files

FileInputStream can be used to read text files as well:

class TestFile{
public TestFile(){
FileInputStream in = null;
StringBuilder sb = new StringBuilder();
int x = 0;
try{
in = new FileInputStream("test2.txt");
while((x = in.read()) != -1){
sb.append((char)x);
}
in.close();
System.out.println(sb.toString());
}catch(Exception e){
System.out.println(e.toString());
}
}
}