java读取中文文件乱码问题 结果如图显示;我用了网上的设置编码字符集为utf8,结果还是乱码,我的系统字符集是utf8,netbeans字符集也是utf8,这是怎么回事?该怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 图片看不到。LZ说的系统字符集是什么意思?还有,能确保文件中的编码是UTF-8的么? 这个与系统的编码关系不大,主要是你的文件的编码。// 给InputStreamReader指定要读取的文件的编码,读取时就不会出现乱码了. public class TextFileReader { public static void main(String[] args) throws Exception { String filename = "source/demo-gb18030.txt"; String encoding = "gb18030"; printFile(filename, encoding); } // 打印出文件的文本内容, 使用指定的编码读入文件 public static void printFile(String filename, String encoding) throws IOException { InputStreamReader isr = new InputStreamReader(new FileInputStream(filename), encoding); BufferedReader reader = new BufferedReader(isr); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } }} String retxtType1 = new String(retxtType.getBytes("ISO-8859-1"),"utf-8"); 时间显示为“一周前”,“3小时前” 读取一个图片或音乐要用字节流还是用字符流啊, SESSION的疑惑,集群相关 一个很简单的字符串截取问题 请教多维数组的问题. 奇怪的类型转换!!! 请教一下关于 Iterator 的 hasNext() 方法 java 正则表达式中的\G \A \Z如何使用? 怎样创建类链表??急急急,在线等待! 初看JAVA,问个白痴问题。。jdk,sdk,jre都是什么哦?他们有什么联系么??谢谢 字符串匹配 使用EditPlus编译,老是出现奇怪的问题:Exception in thread "main"
LZ说的系统字符集是什么意思?
还有,能确保文件中的编码是UTF-8的么?
// 给InputStreamReader指定要读取的文件的编码,读取时就不会出现乱码了.
public class TextFileReader {
public static void main(String[] args) throws Exception {
String filename = "source/demo-gb18030.txt";
String encoding = "gb18030";
printFile(filename, encoding);
} // 打印出文件的文本内容, 使用指定的编码读入文件
public static void printFile(String filename, String encoding) throws IOException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(filename), encoding);
BufferedReader reader = new BufferedReader(isr);
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}