its giving anThe following code is giving a compilation error of storing charchar into bytebyte. howHow do I store the bytes read by the fin.read()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;j = 0;
FileInputStream fin = new FileInputStream("file.txt");
byte[] b = new byte[100];
do {
i=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? readRead the file in to byte array and then display?