我的问题是,如果我使用String硬编码,答案是正确的,但如果我使用inputed String不工作。 例如:
String variable = " \u0020\uFEB3\uFEE8\uFB93\u0020\uFEBB\uFE92\uFEEE\u0631\u0020";
TextView show = (TextView) findViewById(R.id.preshow);
show.settext(variable );
textview显示:صنگصبور
但:
File filematn = new File(Environment.getExternalStorageDirectory()+File.separator+"SingingStudio/"+songname+"/"+songname+"file.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(filematn));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
String variable = text.toString();
TextView show = (TextView) findViewById(R.id.preshow);
show.settext(variable );
textview显示:\ u0020 \ uFEB3 \ uFEE8 \ uFB93 \ u0020 \ uFEBB \ uFE92 \ uFEEE \ u0631 \ u0020
我该如何解决它。谢谢
答案 0 :(得分:0)
当您在文件中读取时,反斜杠将使用前面的反斜杠进行转义。解决这个问题并不像看起来那么简单,但在这个问题中有所涉及:How to replace \\u by \u in Java String