1File file = new File("filename.bin");
2byte[] fileData = new byte[file.length()];
3FileInputStream in = new FileInputStream(file);
4in.read(fileData):
5in.close();
6// now fileData contains the bytes of the file
7
1String content = "";
2for(byte b : fileData)
3 content += getBits(b);
4// content now contains your bits.
5
1String getBits(byte b)
2{
3 String result = "";
4 for(int i = 0; i < 8; i++)
5 result += (b & (1 << i)) == 0 ? "0" : "1";
6 return result;
7}
8