java讀取csv文件和寫csv示例分享。本站提示廣大學習愛好者:(java讀取csv文件和寫csv示例分享)文章只能為提供參考,不一定能成為您想要的結果。以下是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();
}
}
}