-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallBinaryFiles.java
More file actions
47 lines (36 loc) · 1.22 KB
/
Copy pathSmallBinaryFiles.java
File metadata and controls
47 lines (36 loc) · 1.22 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package binaryFiles;
/**
*
* @author pc
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/** JDK 7+. */
public class SmallBinaryFiles {
final static String FILE_NAME = "e:\\palanca.png";
final static String OUTPUT_FILE_NAME = "e:\\binario\\palanca2.dat";
public static void main(String... aArgs) throws IOException{
SmallBinaryFiles binary = new SmallBinaryFiles();
byte[] bytes = binary.readSmallBinaryFile(FILE_NAME);
log("Small - size of file read in:" + bytes.length);
binary.writeSmallBinaryFile(bytes, OUTPUT_FILE_NAME);
}
byte[] readSmallBinaryFile(String aFileName) throws IOException {
Path path = Paths.get(aFileName);
return Files.readAllBytes(path);
}
void writeSmallBinaryFile(byte[] aBytes, String aFileName) throws IOException {
Path path = Paths.get(aFileName);
Files.write(path, aBytes); //creates, overwrites
}
private static void log(Object aMsg){
System.out.println(String.valueOf(aMsg));
}
}