Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting file/folder list  RSS feed

 
Michael Brewer
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty new to Java. I'm beginning my first foray into using java.io to list contents of a given folder. I think that I need to use the file class and the list method of this class. I've written some code that is probably horribly wrong. Can someone here point me in the right direction?
I guess the following should be referred to psuedo-code instead of code since it doesn't have a chance of running.
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code I always use when wanting to list files, it has the option of recursing through subdirectories too.
2 notes:
- you can have the option to filter on particular filenames (uncomment the test if a file is named *.txt etc)
- if you don't want to recurse through subdirectories, just comment out the recursive call to listFiles()
This should give you a starting point anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!