-1

For some reason this is not working, I'm quite new to java so I am probably being naive.

public class CheckScore extends quiz{
    public void CheckScore() {
        String filename = "Data_CS";{

        try (BufferedReader br = new BufferedReader(new FileReader(filename))){
            String line;
            while ((line = br.readLine()) == "potato") {
                System.out.print("vde");
                System.out.print(line);
            }
            } 
         catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
         catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
       }        
    }
}
  • use `(line = br.readLine()).equals("potato")` if it only read the file if the content of the line is potato. normally you use `(line = br.readLine()) !=null` – XtremeBaumer Apr 26 '17 at 12:53
  • Please try to be more specific with your question; read: http://stackoverflow.com/help/how-to-ask – Florian Moser Apr 26 '17 at 13:00

2 Answers2

0

You are using the wrong equals.

== means are the instances that these variables represent the same.

.equals(value) means are the values that these variables hold equal.

Hope the explanation helped you.

0

With string you can use '==' So you can use this :

 line=br.readLine();
 while ((line.equals("potato")) {
            System.out.print("vde");
            System.out.print(line);
            line=br.readLine();
        }
N.Jourdan
  • 590
  • 2
  • 4
  • 22