当前位置: 编程技术>java/j2ee
java读取csv文件示例分享(java解析csv文件)
来源: 互联网 发布时间:2014-11-04
本文导语: 代码如下:import java.io.*;import java.util.*;public class HandleCsv {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream("test.csv") ));String line;String name;String age;String birthday...
代码如下:
import java.io.*;
import java.util.*;
public class HandleCsv {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream("test.csv")
)
);
String line;
String name;
String age;
String birthday;
while ( (line = br.readLine()) != null ) {
//System.out.println(line);
String[] info = line.split(",");
name = info[0].trim();
age = info[1].trim();
birthday = info[2].trim();
System.out.print(name + "t" + age + "t" + birthday + "n");
}
}
}
csv文件
代码如下:
alice, 22, 1992/03/05
bob, 33, 1981/11/21
cart, 40, 1974/07/13