• Post Reply Bookmark Topic Watch Topic
  • New Topic

Directory Sorting based on desired overall size of files.  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to create a program which will output a list of files determined by size.

For example lets say I have a directory which contains 20 files of various sizes. I want to set a maximum value then generate a listing of files which would fit in the desired maximum value.

What would be the best method for accomplishing this task utilizing Java?

I appreciate any help.
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Start by closing the lid of your computer (or pushing away the keyboard), get out a pencil and paper, and write down how you'd do this "by hand". Once you know how to do it, then, and only then, are you ready to start thinking about code.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Class java.io.File represents a path name, and has methods to list the files and subdirectories in a directory. Create a File object for the directory that contains the files, and call one of the methods to list the files in the directory. Then sort the array of File objects that you get back by file size.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!