[英]How to read not ASCII file?
I've got a txt file with cyrillic symbols. 我有一个带有西里尔文符号的txt文件。 This is how I read:
这是我的读法:
String csvFile = "C:\\Users\\dolgopolov.a\\Desktop\\Список рассылки 14 07 2014.txt";
BufferedReader br = null;
String line = "";
String cvsSplitBy = "\t";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] country = line.split(cvsSplitBy);
System.out.println("Номер: " + country[0]
+ " , Сообщение: " + country[1] + "");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
But the output is wierd: 但是输出很奇怪:
Номер: 9047120386 , Сообщение: ��������� �������! �� ����� ����� ������� ������������� � ������� 2,98 ���., ������� ���������� �������� � ������� 3 ����
So, how can I avoid that? 那么,我该如何避免呢? Do I have to change encoding type or something?
我是否需要更改编码类型或其他内容?
FileReader
使用默认编码,因此您必须使用InputStreamReader
new InputStreamReader(new FileInputStream(filePath), encoding)
StreamReader sr = new StreamReader(stream, Encoding.Unicode); StreamReader sr =新的StreamReader(stream,Encoding.Unicode);
or 要么
string converted = Encoding.BigEndianUnicode.GetString(dataArray); 已转换的字符串= Encoding.BigEndianUnicode.GetString(dataArray); where is dataArray your array of bytes
dataArray在哪里,您的字节数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.