I need to burn some booleans into a file, and then retrieve them. I can write and read one or more bytes with Classes java.io.FileInputStream
and java.io.FileOutputStream
, so I need to convert 1 byte to an array of 8 booleans, and convert one array of 8 booleans to 1 byte, like this:
public static boolean[] byteToBooleanArray(byte b) {
boolean[] array = new boolean[8];
//O que colocar aqui?
return array;
}
public static byte booleanArrayToByte(boolean[] array) {
if (array.length != 8) throw new IllegalArgumentException();
byte b;
//O que colocar aqui?
return b;
}
Note: I wish I did not have to download a library.