/* #============================================================================= # # copyright (c) 2009 Origin Enterprise Solution LTD. # #============================================================================= # File name: WriteAndCopyFile.java # File description: #============================================================================= # Date Name Action Description of Change # 2011-4-20 liqz 创建 实现对文件的操作(From Shaangu) #============================================================================= */ package com.connor.lidy.task.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.FileInputStream; public class WriteAndCopyFile { /** * Creates a new instance of WriteAndCopyFile. */ public WriteAndCopyFile() { } /** * writeFile:写相关信息到文本文件中 * @param @param fileName 文件全路径名称 true是增加。 * @param @param append 是否附加到文件结尾 * @param @param content 文件内容 * @since CodingExample Ver 1.1 */ public void writeFile(String fileName, boolean append, String content) { FileOutputStream fos; try { fos = new FileOutputStream(fileName, append); fos.write(content.getBytes()); fos.close(); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } } /** * copyFile:实现文件的Copy * * @param @return 设定文件 * @return String 对象类型 * @throws * @since CodingExample Ver 1.1 */ public static void copyFile(String src, String dest) throws IOException { FileInputStream in = new FileInputStream(src); File file = new File(dest); if (!file.exists()) file.createNewFile(); FileOutputStream out = new FileOutputStream(file); int c; byte buffer[] = new byte[1024]; while ((c = in.read(buffer)) != -1) { for (int i = 0; i < c; i++) out.write(buffer[i]); } in.close(); out.close(); } }