I am trying to scan a file to an array list then search any word via user input on any line and print the result with line number the word was found on. I am new to Java and this is where I am at.....


public static void main(String[] args) throws FileNotFoundException, IOException { Scanner input = new Scanner(System.in); BufferedReader lineReader = new BufferedReader(new FileReader("C://project//myinput.txt")); String lineText = null; int lineNumber = 1; ArrayList listLines = new ArrayList(); while((lineText = lineReader.readLine()) !=null){ listLines.add(lineText); System.out.println(lineNumber+++""+lineText+""); } lineReader.close(); boolean exist= true; System.out.println("Input Word"); String in = input.nextLine(); //while() for(String item: listLines){ // if(listLines.contains(in)) {System.out.println(""+exist); break; } else{ exist = false; System.out.println(""+exist); break; } } //////I was just using the code with boolean to test but I really need to print the result of the search with the line/////////////////with the line number it was found on..... }}

Edited by Dogstopper:

More...