开发者

can i read windows-1256 file in java?

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜