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();
    }

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.