-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileOperations.java
More file actions
65 lines (56 loc) · 1.85 KB
/
Copy pathFileOperations.java
File metadata and controls
65 lines (56 loc) · 1.85 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOperations {
public static void fileCopier(String sourcePath,String dest) throws IOException{
long startTime = System.currentTimeMillis();
final int EOF = -1;
File file = new File(sourcePath);
if(file.exists()){
FileInputStream fi = new FileInputStream(file);
BufferedInputStream bi = new BufferedInputStream(fi,99999);
FileOutputStream fo = new FileOutputStream(dest);
BufferedOutputStream bo = new BufferedOutputStream(fo,99999);
int singleByte = bi.read();
while(singleByte!=EOF){
//System.out.print((char)singleByte);
bo.write(singleByte);
singleByte = bi.read();
}
bi.close();
bo.close();
fi.close();
fo.close();
System.out.println("File Copy Done...");
long endTime = System.currentTimeMillis();
System.out.println("Total Time Taken "+(endTime-startTime));
}
}
public static void readFile(String filePath) throws IOException{
final int EOF = -1;
File file = new File(filePath);
if(file.exists()){
FileInputStream fi = new FileInputStream(file);
int singleByte = fi.read();
while(singleByte!=EOF){
System.out.print((char)singleByte);
singleByte = fi.read();
}
fi.close();
}
}
public static boolean writeFile(String filePath, String data) throws IOException{
FileOutputStream fout = new FileOutputStream(filePath,true);
fout.write(data.getBytes());
fout.close();
return true;
}
public static void main(String[] args) throws IOException {
fileCopier("E:\\TestingFileHandling\\abcd.dat", "E:\\TestingFileHandling\\xyz.dat");
//readFile("D:\\JavaWeekEnd10to12\\FileHandling\\src\\FileOperations.java");
//writeFile("E:\\TestingFileHandling\\Sample.txt", "Hello How are You");
}
}