0

What is wrong with my code. it poulates the arraylist with only the filename "c:\testfile.txt" i need it to populate it with the contents of the file.

private ArrayList<String> Files2Delete = new ArrayList<String>();
private String fName = "c:\\TestFile.txt";

private void fileCollection ()
    {
        Scanner in = new Scanner(fName);
        int i = 1;
        
        while (in.hasNextLine())
        {
            String line = in.nextLine();
            Files2Delete.add(line);
            i++;
        }
        in.close();
    }
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by dickersonka
0

The scanner constructor takes a string as a source to read from, the string is not a filepath

use this

File file = new File(fName);

Scanner in = new Scanner(file);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.