Read a file character by character/UTF8: Difference between revisions
Content deleted Content added
Line 378: | Line 378: | ||
public class FileUtil { |
public class FileUtil { |
||
FileReader reader; |
|||
⚫ | |||
⚫ | |||
/** cast the returned value to 'char' */ |
|||
StringBuilder string = new StringBuilder(); |
|||
int next() throws IOException { |
|||
⚫ | |||
try { |
try { |
||
⚫ | |||
/* 'read' will return 0 through 0xffff, and -1 for EOS */ |
/* 'read' will return 0 through 0xffff, and -1 for EOS */ |
||
value = (char) reader.read(); |
|||
} catch (IOException exception) { |
|||
} finally { |
|||
reader.close(); |
reader.close(); |
||
throw exception; |
|||
} |
} |
||
return |
return value; |
||
} |
|||
⚫ | |||
⚫ | |||
} |
|||
void close() throws IOException { |
|||
reader.close(); |
|||
} |
} |
||
} |
} |