我正在尝试读取一个法语文件的内容(逐个字符),并检查它们的ASCII值以执行一些操作。对于包含英文字母的内容,一切正常,但对于像àéèé这样的字符,我遇到了一些问题。
例如,如果我的文件内容是français,则输出为français。 这里,我附上我的代码,请看一下并指导我如何解决这个问题。
例如,如果我的文件内容是français,则输出为français。 这里,我附上我的代码,请看一下并指导我如何解决这个问题。
File file = new File("C:\text.txt");
fis = new BufferedInputStream(new FileInputStream(file));
char current;
char org;
while (fis.available() > 0) {
current = (char) fis.read(); // to read character
// from file
int ascii = (int) current; // to get ascii for the
// character
org = (char) (ascii); // to get the actual
// character
if (ascii == 10) {
resultString = resultString.append(",'"
+ strCompCode + "'");
dbhelpher.addDataRecord(resultString.toString());
resultString.setLength(0);
} else if (ascii != 13) { // other than the ascii
// 13, the character are
// appended with string
// builder
resultString.append(org);
}
}
fis.close();
在这里,我需要像文本文件中一样读取法语字符。非常感谢您的建议。提前致谢。
InputStreamReader
,并且逐行读取。请注意,ASCII不包括任何带重音的字符。此外,请在以后更加注重格式化你的源代码。 - Jon Skeet