-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.java
executable file
·52 lines (45 loc) · 1.39 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package copyfiles;
import java.io.*;
/**
*
* @author cherkashinv
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
copyFile("c:\\test.xml","c:\\2.xml");
}
private static boolean copyFile(String source, String destination){
boolean return_value=false;
try{
File file_source = new File(source);
File file_destination = new File(destination);
InputStream in = new FileInputStream(file_source);
//For Append the file.
// OutputStream out = new FileOutputStream(f2,true);
//For Overwrite the file.
OutputStream out = new FileOutputStream(file_destination);
// buffer size
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
return_value=true;
}catch(FileNotFoundException ex){
System.out.println("File ("+source+") not found: "+ex.getMessage());
}catch(IOException e){
System.out.println("IOException:"+e.getMessage());
}
return return_value;
}
}