Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

working with files, don't know where to start  RSS feed

 
Yotam Ohayon
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there
we got an assignment in school to write a java program that can handle files. when i invoke the program the two arguments are a directory to work in and the command.
i need to know how to list/store in a java collection the files in a given directory, but i don't know where to start. can someone point me to a guide explaining exactly that?
also, we were recommended to use a treeset to store all the files in the directory. is there a better option?

thanks a lot
Yotam
 
Stephan van Hulst
Saloon Keeper
Posts: 7719
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Yotam,

You may want to read the documentation for java.io.File. It should have a method which will help you a lot.

Also, there might be a better option than TreeSet to store the files, but it depends on your requirements. TreeSet will sort your files, so this is probably the reason it was recommended to you.
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good place to start would be the java.io.File API. I'm surprised your instructor didn't point you in that direction already. The collection you use to store the file list sort of depends on what you're going to do with it. However, a directory structure is a tree and file names have to be unique, at least within a directory, so TreeSet seems like a good choice.

ETA: great minds think alike!
 
Stephan van Hulst
Saloon Keeper
Posts: 7719
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Yotam Ohayon
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that helped a lot!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!