| | |
arraylist problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2007
Posts: 159
Reputation:
Solved Threads: 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.
Java Syntax (Toggle Plain Text)
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(); }
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 138
The scanner constructor takes a string as a source to read from, the string is not a filepath
use this
use this
Java Syntax (Toggle Plain Text)
File file = new File(fName); Scanner in = new Scanner(file);
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Urgent!
- Next Thread: HELP pleeeeeeeeez ???
Views: 359 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






