java读取csv文件和写csv示例分享
import java.io.bufferedreader;
import java.io.bufferedwriter;
import java.io.file;
import java.io.fileinputstream;
import java.io.filenotfoundexception;
import java.io.filereader;
import java.io.filewriter;
import java.io.ioexception;
import java.io.inputstreamreader;
public class csv{
public static void main(string[] args) throws ioexception {
file outfile = new file("d://new_car.csv");//存储到新文件的路径
try {
inputstreamreader isr = new inputstreamreader(new fileinputstream("d://car.csv"));//待处理数据的文件路径
bufferedreader reader = new bufferedreader(isr);
bufferedwriter bw = new bufferedwriter(new filewriter(outfile));
string line = null;
while((line=reader.readline())!=null){
string item[] = line.split(",");
/*
*信息处理块
*/
bw.newline();//新起一行
bw.write(""+","+"");//写到新文件中
}
bw.close();
} catch (filenotfoundexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}
}
上一篇: springmvc处理响应数据的解析