I want to read an Arabic text file encoded in windows-1256 using Java (on the windows platform)
Any sug开发者_C百科gestions?
If your JVM supports that encoding, then yes, you can easily do that:
Reader r = new InputStreamReader(new FileInputStream(theFile), "Windows-1256");
BufferedReader buffered = new BufferedReader(r);
try {
String line;
while ((line = buffered.readLine()) != null) {
// handle each line
}
} finally {
buffered.close();
}
Something like:
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("myfile.txt"), "windows-1256"));
Should work.
To read from a FileInputStream with another character set than the platform default, use an InputStreamReader:
http://download.oracle.com/javase/6/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream,%20java.lang.String)
精彩评论