写StringBuffer到文件

/* * 将结果写入文件 */ private static void createFile(File file, StringBuffer buffer) { try { File newFile = new File(file.getAbsolutePath() + ".txt"); if (newFile.exists())// 存在,则删除 if (!newFile.delete())// 删除成功则创建 { System.err.println("删除文件" + newFile + "失败"); } if (newFile.createNewFile()) {// 创建成功,则写入文件内容 PrintWriter p = new PrintWriter(new FileOutputStream(newFile .getAbsolutePath())); p.write(buffer.toString()); p.close(); } else { System.err.println("创建文件:" + newFile + "失败"); } } catch (Exception e) { e.printStackTrace(); } } 

你可能感兴趣的:(exception,File,buffer)