package baidu.com.commontools.utils;


import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class FileUtils {

    public static String readStreamAsString(InputStream is) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        StringBuilder result = new StringBuilder();
        String line;

        boolean first = true;
        while ((line = reader.readLine()) != null) {
            if (!first) {
                result.append('\n');
            } else {
                first = false;
            }
            result.append(line);
        }

        return result.toString();
    }

    public static void saveStreamToFile(InputStream is, File file) throws IOException {
        File dirFile = file.getParentFile();
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }

        FileOutputStream fos = new FileOutputStream(file);
        try {
            byte[] buffer = new byte[1024 * 32];
            int len;

            while ((len = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            fos.flush();
        } finally {
            close(fos);
            close(is);
        }
    }

    public static void close(Closeable target) {
        try {
            if (target != null)
                target.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void deleteFile(String path, String fileName) {
        new File(path, fileName).delete();
    }
}

@@ -106,24 +106,56 @@
 va.io.File;%0A
+import java.io.FileInputStream;%0A
 import java.
@@ -265,16 +265,45 @@
 Reader;%0A
+import java.io.OutputStream;%0A
 %0A%0Apublic
@@ -1756,11 +1756,581 @@
 );%0A    %7D
+%0A%0A    public static void copy(File src, File dst) throws IOException %7B%0A        InputStream in = new FileInputStream(src);%0A        try %7B%0A            OutputStream out = new FileOutputStream(dst);%0A            try %7B%0A                // Transfer bytes from in to out%0A                byte%5B%5D buf = new byte%5B1024%5D;%0A                int len;%0A                while ((len = in.read(buf)) %3E 0) %7B%0A                    out.write(buf, 0, len);%0A                %7D%0A            %7D finally %7B%0A                out.close();%0A            %7D%0A        %7D finally %7B%0A            in.close();%0A        %7D%0A    %7D
 %0A%7D%0A

add FileUtil#copy