arraylist problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2007
Posts: 159
Reputation: mrjoli021 is an unknown quantity at this point 
Solved Threads: 0
mrjoli021 mrjoli021 is offline Offline
Junior Poster

arraylist problem

 
0
  #1
Oct 28th, 2008
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.

  1. private ArrayList<String> Files2Delete = new ArrayList<String>();
  2. private String fName = "c:\\TestFile.txt";
  3.  
  4. private void fileCollection ()
  5. {
  6. Scanner in = new Scanner(fName);
  7. int i = 1;
  8.  
  9. while (in.hasNextLine())
  10. {
  11. String line = in.nextLine();
  12. Files2Delete.add(line);
  13. i++;
  14. }
  15. in.close();
  16. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 138
dickersonka dickersonka is offline Offline
Veteran Poster

Re: arraylist problem

 
0
  #2
Oct 28th, 2008
The scanner constructor takes a string as a source to read from, the string is not a filepath

use this
  1. File file = new File(fName);
  2.  
  3. Scanner in = new Scanner(file);
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 359 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC