Read a file character by character/UTF8: Difference between revisions

Line 378:
 
public class FileUtil {
FileReader reader;
String readFile(String path) throws IOException {
FileReader reader = new FileReader(path, UTF_8);
/** cast the returned value to 'char' */
StringBuilder string = new StringBuilder();
int next() throws IOException {
int value;
try {
int value;
/* 'read' will return 0 through 0xffff, and -1 for EOS */
while ((value = (char) reader.read()) != -1);
} catch (IOException string.append((charexception) value);{
} finally {
reader.close();
throw exception;
}
return string.toString()value;
}
Stringvoid readFileopen(String path) throws IOException {
FileReader reader = new FileReader(path, UTF_8);
}
void close() throws IOException {
reader.close();
}
}
118

edits