java读取csv文件示例分享(java解析csv文件)
程序员文章站
2024-02-24 08:44:58
复制代码 代码如下:import java.io.*;import java.util.*;public class handlecsv {public static vo...
复制代码 代码如下:
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