Netbeans
文件查看器有问题。我有一个阿拉伯语字符串,每个字母的顶部都有重音符号。当我从字符串中删除重音符号时,字母会正确显示。然而,当我用重音写字符串时,它会以某种方式变得混乱(不正确(。
这是正在发生的事情的一个例子:
- 不带重音符号的文本(正确(:
بسم الله الرحمن الرحيم
- 带有重音符号的文本(不正确(:
it shows broken, but if i copy it here it prints correctly
- 应该是这样的(正确(:
بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
我写的代码是读取一个包含阿拉伯字符串及其重音符号的文本文件,然后将其正确写入新文件,最后删除旧文件。这是代码:
public void arabicReformer(File disordered) {
File output = new File("data/temp2.txt");
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(disordered), "UTF8"));
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(output), "UTF8"));
String line;
while ((line = br.readLine()) != null) {
bw.write(line.trim() + "n");
}
br.close();
bw.close();
} catch (UnsupportedEncodingException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
output.renameTo(disordered);
}
附言:当我用这里的重音复制不正确的阿拉伯字符串时,它打印正确!
祝你好运,我的朋友:(请尝试使用此代码读取和打印阿拉伯字符,并确保文件的原始格式为UTF-8。
public void unicodeShow(String fileName) throws UnsupportedEncodingException, FileNotFoundException, IOException{
Reader reader = new InputStreamReader(new FileInputStream(fileName), "utf-8");
BufferedReader br = new BufferedReader(reader);
String a=br.readLine();
System.out.println(a);
}