java中的编写者通过windows-1256编码

时间:2018-04-30 08:10:48

标签: java character-encoding

我正在试用JAVA 8,因为" windows-1256"文件写作 我的最后一次尝试是:

  String win1256="...";

//

  File file = new File ("C:\file1.txt");
  OutputStreamWriter   os = new OutputStreamWriter (new 
  FileOutputStream(file),"windows-1256");
  os.write(win1256);

或:

  FileOutputStream out = new FileOutputStream("C:\file1.txt");
  out.write(win1256.getBytes("windows-1256"));

但是没有工作和输出文件是不可读的" ??? ..."

1 个答案:

答案 0 :(得分:0)

更改是:

byte[] originalBytes; // Here the sequence of bytes representing the UTF-8 encoded string
Encoding enc = Encoding.GetEncoding("windows-1256");
byte[] newBytes = enc.GetBytes(Encoding.UTF8.GetString(originalBytes));