java - How to get the actual size of selected files and folders? -
jfilechooser filechooser = new jfilechooser(); filechooser.setfileselectionmode(jfilechooser.files_and_directories); file selectedfile = filechooser.getselectedfile(); long sizeofdirectory = fileutils.sizeofdirectory(selectedfile);
this isn't generating actual size of selected files , folders, gives value less actual value.
i selecting more 1 folder @ once.
how fix issue?
actually selecting 2 folders, issue happens
that's because jfilechooser#getselectedfile
return one. need use jfilechooser#getselectedfiles
, loop on them, calling fileutils.sizeofdirectory
each file , summing results
file[] selectedfiles = filechooser.getselectedfiles(); long sizeofdirectory = 0; (file file : selectedfiles) { sizeofdirectory += fileutils.sizeofdirectory(file); }
(you should beware getselectedfile
, getselectedfiles
may return null
)
Comments
Post a Comment