代碼如下:
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();
}
}
}