Home > Java > JavaBase > body text

How to solve the problem of garbled characters when reading csv files in Java

Release: 2019-12-30 15:53:39
Original
5968 people have browsed it

How to solve the problem of garbled characters when reading csv files in Java

csv文件默认编码为ANSI,java读取CSV出现乱码主要是编码不一致问题。(推荐:java视频教程

DataInputStream in = new DataInputStream(new FileInputStream(new File("d:\\*.csv")));
BufferedReader br= new BufferedReader(new InputStreamReader(in,"GBK"));//这里如果csv文件编码格式是utf-8,改成utf-8即可
Copy after login

InputStreamReader类是从字节流到字符流的桥接器:它使用指定的字符集读取字节并将它们解码为字符。 它使用的字符集可以通过名称指定,也可以明确指定,或者可以接受平台的默认字符集。

BufferedReader类从字符输入流中读取文本并缓冲字符,以便有效地读取字符,数组和行。Reader构成的对象是字符对象,每次的读取请求都会涉及到字节读取解码字符的过程,而BufferedReader类中有设计减少这样的解码次数的方法,进而提高转换效率。

更多java知识请关注java基础教程栏目。

The above is the detailed content of How to solve the problem of garbled characters when reading csv files in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!