The following code is  giving a compilation error of storing char into byte. How do store the bytes read by the fin.read() function into a byte array and print it?
import java.io.FileInputStream;
class IO {
    public static void main(String args[]) {
        int i;
        int j = 0;
        FileInputStream fin = new FileInputStream("file.txt");
        byte[] b = new byte[100];
        do {
            i = fin.read();
            j++;
            b[j] = (char) i;
        } while (i != -1);
        System.out.println(b);
    }
}
Output:
possible loss of precision
found   : char
required: byte
            b[j] =(char) i;
                  ^
1 error
How do I make it work? Read the file in to byte array and then display?


charis anintnot abyte, but why are you doing this? i think you have a bigger problem here.