• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using listFiles to read files in directory  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm a beginner and am trying to read through a directory and put the files into the scanner so i can get data from them. here is what i have so far. i'm not sure if this is the right approach at all, but doing it this way gives me one error (incompatible types on this line: "for(String name : dir1List)" required: String, found: File). If anyone could make any suggestions it would be greatly appreciated!


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nerd dork wrote:gives me one error (incompatible types on this line: "for(String name : dir1List)" required: String, found: File).


The error message is telling you exactly what's wrong. The String name : part says that you're going to be iterating over a bunch of Strings, but dir1List contains a bunch of Files, not Strings. So you need to either use File as your iteration variable type, or get a list of Strings instead of Files to start with.
 
nerd dork
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use File as iteration value though, it says this: no suitable constructor found for (File, File) in the part where it makes the directory file (new File(name, name2))
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!