Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package recursion;
- import java.io.File;
- public class DirectorySize {
- public static void main(String[] args) {
- // Find the size of directory (sum of the sizes of all files in the directory
- // you can test the program here, I didn't write the code to test it, but it works I think
- }
- public static long getSize(File file) {
- long size = 0;
- if(file.isDirectory()) {
- File[] files = file.listFiles();
- for(int index=0; files != null && index<files.length; index++) {
- size += getSize(files[index]);
- }
- }
- else {
- size+=file.length();
- }
- return size;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement