Hello,
Please point me in the right correction. I am trying to read the test.txt file and print all the lines that contains the string "Yellow".
Thanks!
//package textfiles; import java.io.*; class ReadFromAnsiFile { public static void main ( String[] args) { String fileName = "test.txt"; //string variable to hold the name of a text file: String line; try { BufferedReader in = new BufferedReader( new FileReader( fileName ) ); line = in.readLine(); // Reads a line of text, returns a null if nothing is there. while (line != null ) { if (line.nextLine().equals("Yellow")) { System.out.println (line); line = in.readLine(); } } in.close(); } catch ( IOException e ) { System.out.println(e.getMessage() ); } } }