programming-examples/java/XML/No catch read ascii file.java

35 lines
636 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
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 );
}
}