追加写入的方式的 写 csv文件



package com.kevin.test3;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.catalina.connector.OutputBuffer;
import org.junit.Test;

public class CSVTest {
	
	public File createFileAndColName(String filePath, String fileName,  String[] colNames){
		File csvFile = new File(filePath, fileName);
		PrintWriter pw = null;
		try {			
			pw = new PrintWriter(csvFile, "GBK");		
			StringBuffer sb = new StringBuffer();
			for(int i=0; i> data){		
		try {
			
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile, true), "GBK"), 1024);
			for(int i=0; i list = new ArrayList<>();
		list.add("1啊");
		list.add("2啊");
		list.add("3啊");
		list.add("4阿");
		List list2 = new ArrayList<>();
		list2.add("12");
		list2.add("22");
		list2.add("32");
		list2.add("42");
		List> data = new ArrayList<>();
		data.add(list);
		data.add(list2);
		appendDate(csvFile, data);
		appendDate(csvFile, data);		
		
		System.out.println( System.getProperty("file.encoding") );
	}
	
	
}





你可能感兴趣的:(Java)