int c = read();
// if we're already at the end of the file
- // don't even return the empty string
- if( c == -1 ) {
+ // or there is an error, don't even return
+ // the empty string
+ if( c <= 0 ) {
return null;
}
- while( c != '\n' && c != -1 ) {
+ while( c != '\n' && c > 0 ) {
line += (char)c;
- c = read();
+ c = read();
}
return line;
--- /dev/null
+public class FileInputStreamTest {
+ static public void main( String[] args ) {
+ FileInputStream in = new FileInputStream( "test.txt" );
+
+ System.out.println( "#####################" );
+ String line = in.readLine();
+ while( line != null ) {
+ System.out.println( line );
+ line = in.readLine();
+ }
+ System.out.println( "#####################" );
+ in.close();
+ }
+}
\ No newline at end of file