package kousuanti; import java.io.*; public class SaveCsv { public void save(String strings[]){ String filePath="D:\\Idea\\CSV\\"; File file = new File(filePath + "KouSuanTi_01.csv"); try { //如果存在,则删除,新建文件 if (file.exists()) { file.delete(); } file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } FileOutputStream out=null; OutputStreamWriter osw=null; BufferedWriter bw=null; try { out = new FileOutputStream(file); osw = new OutputStreamWriter(out,"UTF-8"); bw =new BufferedWriter(osw); //写入数据 for(int i=0;i< strings.length;i++) { bw.append(strings[i]); bw.append("\r"); } } catch (Exception e) { e.printStackTrace(); }finally{ try { if(bw!=null) bw.close(); bw=null; if(osw!=null) osw.close(); osw=null; if(out!=null) out.close(); out=null; } catch (IOException e) { e.printStackTrace(); } } } }