I read bytes from a binary file. When reading, I convert byte 0 to character 0, byte 1 to character 1. But in this line
OP[i] = (char)((f1[i] == 0) ? '0' : '1'); an error occurs, the compiler says that char cannot be converted to a String. I do not understand what I did wrong. Help me find a bug.
String OPER = "00100011101"; byte[] bytes = new byte[OPER.length()]; for (int i = 0; i < OPER.length(); i++) { bytes[i] = (byte) ((OPER.charAt(i) == '0') ? 0 : 1); //System.out.println(bytes[i]); } try (FileOutputStream fos = new FileOutputStream(new File("someFile.dat"))) { fos.write(bytes); fos.close(); } FileInputStream f1 = new FileInputStream("someFile.dat"); int size = f1.available(); String[] OP = new String[size]; System.out.println("Total Available Bytes: " + size); for (int i = 0; i < size; i++) { OP[i] = (char)((f1[i] == 0) ? '0' : '1'); System.out.print( f1.read()); }