测试1

public static boolean copy(String file1, String file2) {  
        try // must try and catch,otherwide will compile error  
        {  
            // instance the File as file_in and file_out  
            java.io.File file_in = new java.io.File(file1);  
            java.io.File file_out = new java.io.File(file2);  
            FileInputStream in1 = new FileInputStream(file_in);  
            FileOutputStream out1 = new FileOutputStream(file_out);  
            byte[] bytes = new byte[1024];  
            int c;  
            while ((c = in1.read(bytes)) != -1)  
                out1.write(bytes, 0, c);  
            in1.close();  
            out1.close();  
            return (true); // if success then return true  
        } catch (Exception e) {  
            System.out.println("Error!");  
            return (false); // if fail then return false  
        }  
    }

猜你喜欢

转载自wushipan-easy.iteye.com/blog/2355854