java读取txt文本中文乱码问题
2018-04-03 15:57
295 查看
java读取txt文本中如含有中文,可能会出现乱码,解决方案是:
1.要统一编码,java工程的编码,txt文本编码,java工程中的java文本编码都统一为utf-8;
2.利用 InputStreamReader(new FileInputStream(fileUrl), "utf-8")将文本再次设置为utf-8
InputStreamReader isr;
try {
isr = new InputStreamReader(new FileInputStream(fileUrl), "utf-8");
BufferedReader read = new BufferedReader(isr);
String s=null;
List<String> list = new ArrayList<String>();
while((s=read.readLine())!=null)
{
//System.out.println(s);
if(s.trim().length()>1){
list.add(s.trim());
}
}
System.out.println("OK!");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
1.要统一编码,java工程的编码,txt文本编码,java工程中的java文本编码都统一为utf-8;
2.利用 InputStreamReader(new FileInputStream(fileUrl), "utf-8")将文本再次设置为utf-8
InputStreamReader isr;
try {
isr = new InputStreamReader(new FileInputStream(fileUrl), "utf-8");
BufferedReader read = new BufferedReader(isr);
String s=null;
List<String> list = new ArrayList<String>();
while((s=read.readLine())!=null)
{
//System.out.println(s);
if(s.trim().length()>1){
list.add(s.trim());
}
}
System.out.println("OK!");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
相关文章推荐
- java读取txt文本中文乱码问题
- Java IO读取文件中文乱码问题
- 【Java IO知识】读取中文乱码问题解决
- 解决Java读取properties文件中文乱码的问题
- Java 读取中文的乱码问题
- Java读取properties文件中文乱码问题的解决
- java 向文件中写中文和读取乱码问题
- java读取access中文乱码问题
- Java 解决FileInputStream读取中文时乱码的问题
- Java读取文件 解决中文乱码问题
- java读取默认编码是ansi的文本文件时,解决中文乱码问题
- Java读取文本文件中文乱码问题
- Java IO读取文件中文乱码问题
- Java读取文本文件中文乱码问题
- Java读取文本文件中文乱码问题 .转载
- java读取文件中文乱码问题
- 使用java.nio及其子包中的类SocketChanel完成如下功能:读取www.baidu.com等网页的内容,打印到控制台,避免中文乱码问题。
- Java读取中文的乱码问题
- Java 读取ANSI文件中文乱码问题解决方式
- 面对java逐行读取txt文本中文乱码我们必须要了解解决方案