You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
636 B
Java

No catch read ascii file
package com.ack.j2se.io;
import java.io.FileReader;
public class NoCatchReadAsciiFile {
public static void main( String[] args ) throws Exception {
String myFile = "readme.txt";
StringBuffer buf = null;
FileReader fr = null;
try {
fr = new FileReader( myFile );
int theChar;
buf = new StringBuffer();
while( ( ( theChar = fr.read() ) != -1 ) ) {
buf.append( (char) theChar );
}
}
finally {
if( fr != null )
fr.close();
}
if( buf != null )
System.out.println( buf );
}
}