Codice:
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class BitProva {
public static void main(String[] a) {
try {
FileChannel channel = new FileInputStream("c:\\ciao.txt").getChannel();
int numBytes = (int)channel.size();
ByteBuffer buffer = ByteBuffer.allocate(numBytes);
channel.read(buffer);
buffer.flip();
for(int i = 0; i < numBytes; i++) {
String binDigits = Integer.toBinaryString(buffer.get(i));
System.out.println(binDigits);
}
channel.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
1100011
1101001
1100001
1101111