954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

arraylist problem

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();
    }
mrjoli021
Junior Poster
172 posts since Mar 2007
Reputation Points: 7
Solved Threads: 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);
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You