I have a file saved as utf-8 (actually saved by my application). How do you read it by character?
File file = new File(folder+name);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
Two options are possible:
char c = dis.readByte()
char c = dis.readChar()
- The first option works as long as you have saved only ascii characters, i.e. English.
- The second option reads the first and second bytes of the file as one character.
The source file is written as follows:
File file = File.createTempFile("file", "txt");
FileWriter fstream = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fstream);
source
share