The code below reads from a file helpFile.txt and checks for an index represented by # . The variable read from the file is stored in the integer c and compared with # if the read character is # without casting the integer into character. I want to know if the comparison is valid as the compiler is not showing any error. Also, suppose # is found by the program in the file and a string called topic immediately follows # and it is read using readLine(). Will the String info = br.readLine() be just topic or # + topic ? Sorry for such a lengthy question. Help much appreciated.
boolean help 内容:
private BufferedReader br;
private String info, topic;
private static PrintWriter pw = new PrintWriter(System.out, true);
int c;
br = new BufferedReader(new FileReader("helpFile.txt"));
try{
do{
//read characters until # is found
c = br.read();
if(***c== # ***){ //check if the character is #
pw.println(c);
if((**topic=br.readLine()**).equalsIgnoreCase(what)){ //check if what string is equal to s which is the string after #
while((info=br.readLine())!=null){ //print info until the end of info
if(info!=null)
pw.println(info);
}
return true;
}
}
}
while(c!=-1);
}
catch(IOException ex){
pw.println("File error.");
ex.printStackTrace();
try{
br.close();
}
catch(IOException e){
pw.println("Error closing file.");
e.printStackTrace();
}
return false;
}
try{
br.close();
}
catch(IOException ex){
pw.println("Error closing file.");
ex.printStackTrace();
}
return false; //topic not found
}