I'm trying to read certain text file and when I find certain word, I should do another criteria,
in my code (will follow), I get an error, "Type mismatch: cannot convert from int to String" So, the suggested solution by Eclipse is to make the variable (key) integer instead of String what is the wrong thing here ?
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class JNAL {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("C:/20180918.jrn");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
System.out.println("Total file size to read (in bytes) : "
+ fis.available());
int content;
String key;
/*
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content);
}
*/
while ((key = fis.read()) == "Cash") {
// convert to char and display it
System.out.print((String) key);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}