-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryFile.java
More file actions
38 lines (34 loc) · 979 Bytes
/
BinaryFile.java
File metadata and controls
38 lines (34 loc) · 979 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
34
35
36
37
38
package btp.oneP;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class BinaryFile {
public static byte[] read(File bFile) throws IOException{
BufferedInputStream bf = new BufferedInputStream(new FileInputStream(bFile));
try{
byte[] data = new byte[bf.available()];
bf.read(data);
return data;
}finally{
bf.close();
}
}
public static byte[] read(String bFile) throws IOException{
return read(new File(bFile).getAbsoluteFile());
}
public static void main(String[] args) throws IOException {
byte[] bytes = read("E:\\workspaces\\NewWork\\Study\\src\\btp\\oneP\\BinaryFile.java");
Map<Byte,Integer> map = new HashMap<Byte,Integer>();
for(byte b : bytes){
if(null == map.get(b)){
map.put(b, 1);
}else{
map.put(b, map.get(b)+1);
}
}
System.out.println(map);
}
}