S
Stryder
Hi. How do I read and write a file using UTF8?
I have a file that's UTF-8 - for development purposes it just consists
of a space, an mdash (hex 8212) and another space. I'm using the
following Java code...
import java.io.*;
class UTF8 {
public static void main(String[] args) throws Exception {
System.setProperty("file.encoding", "UTF-8");
File xmlFile = new File("mdash.txt");
FileInputStream fileInputStream = new FileInputStream
(xmlFile);
byte[] fileBufferByteArray = new byte[(int) xmlFile.length()];
fileInputStream.read(fileBufferByteArray);
String fileBufferString = new String(fileBufferByteArray,
"UTF-8");
PrintWriter p = new PrintWriter(System.out);
p.print(fileBufferString);
p.close();
}
}
and running it like this...
java UTF8 > x
but x always ends up containing " ? " (a space, a question mark, then
a space). How can I make this work?
Thanks in advance for your help!
Ralph
I have a file that's UTF-8 - for development purposes it just consists
of a space, an mdash (hex 8212) and another space. I'm using the
following Java code...
import java.io.*;
class UTF8 {
public static void main(String[] args) throws Exception {
System.setProperty("file.encoding", "UTF-8");
File xmlFile = new File("mdash.txt");
FileInputStream fileInputStream = new FileInputStream
(xmlFile);
byte[] fileBufferByteArray = new byte[(int) xmlFile.length()];
fileInputStream.read(fileBufferByteArray);
String fileBufferString = new String(fileBufferByteArray,
"UTF-8");
PrintWriter p = new PrintWriter(System.out);
p.print(fileBufferString);
p.close();
}
}
and running it like this...
java UTF8 > x
but x always ends up containing " ? " (a space, a question mark, then
a space). How can I make this work?
Thanks in advance for your help!
Ralph