-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJPGRecovery.java
More file actions
33 lines (24 loc) · 920 Bytes
/
JPGRecovery.java
File metadata and controls
33 lines (24 loc) · 920 Bytes
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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class JPGRecovery {
// For now, this main method simply copies the file untill it finds a byte "11111111".
// It does serve as a good starting point and illustrates
// the use of DataInputStream and DataOutputStream.
public static void main(String[] args) {
try {
DataInputStream in = new DataInputStream(new FileInputStream(args[0]));
DataOutputStream out = new DataOutputStream(new FileOutputStream("firstPartOfFile.img"));
byte byte1 = in.readByte();
while ((in.available() > 0) && (byte1 != (byte) 0xff)) {
out.writeByte(byte1);
byte1 = in.readByte();
}
out.writeByte(byte1);
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
}
}