-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathReadDemo.java
More file actions
40 lines (37 loc) · 1.27 KB
/
ReadDemo.java
File metadata and controls
40 lines (37 loc) · 1.27 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
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class ReadDemo {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// Step -1 Open a File
final int EOF = -1; // EOF (End of File)
FileInputStream fi =
new FileInputStream("/Users/amit/Documents/testing/TumHiHo.mp3");
BufferedInputStream bi = new BufferedInputStream(fi);
FileOutputStream fo = new FileOutputStream("/Users/amit/Documents/testing/Copy.mp3");
BufferedOutputStream bo = new BufferedOutputStream(fo);
// Step - 2 Read a File
long startTime = System.currentTimeMillis();
//int singleByte = fi.read(); // Read Single Byte
int singleByte = bi.read();
// Loop till reach to EOF
while(singleByte!=EOF){
bo.write(singleByte);
//fo.write(singleByte);
//System.out.print((char)singleByte); // Print the Value
//singleByte = fi.read(); // Read Again the Another Byte
singleByte = bi.read();
}
// Step - 3 Close the File
long endTime = System.currentTimeMillis();
System.out.println("Total Time Taken "+(endTime-startTime));
bi.close();
bo.close();
fi.close();
fo.close();
System.out.println("Done...");
}
}