Read a file character by character/UTF8: Difference between revisions
Content deleted Content added
Line 371: | Line 371: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
<syntaxhighlight |
<syntaxhighlight> |
||
⚫ | |||
import java.io.FileReader; |
import java.io.FileReader; |
||
import java.io.IOException; |
import java.io.IOException; |
||
⚫ | |||
public final class ReadFileByCharacter { |
|||
public static void main(String[] aArgs) { |
|||
String path = "C:/Users/psnow/Desktop/testFile.txt"; |
|||
⚫ | |||
⚫ | |||
while ( ( value = fileReader.read() ) != END_OF_STREAM ) { |
|||
System.out.println((char) value); |
|||
} |
|||
⚫ | |||
ioe.printStackTrace(); |
|||
} |
|||
} |
|||
private static final int END_OF_STREAM = -1; |
|||
public class FileUtil { |
|||
FileReader reader; |
|||
/** cast the returned value to 'char' */ |
|||
int next() throws IOException { |
|||
⚫ | |||
try { |
|||
/* 'read' will return 0 through 0xffff, and -1 for EOS */ |
|||
value = reader.read(); |
|||
⚫ | |||
reader.close(); |
|||
throw exception; |
|||
} |
|||
return value; |
|||
} |
|||
void open(String path) throws IOException { |
|||
⚫ | |||
} |
|||
void close() throws IOException { |
|||
reader.close(); |
|||
} |
|||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{ out }} |
|||
<pre> |
|||
R |
|||
o |
|||
s |
|||
e |
|||
t |
|||
t |
|||
a |
|||
</pre> |
|||
=={{header|jq}}== |
=={{header|jq}}== |