• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help to calculate directory size

 
Ranch Hand
Posts: 83
MS IE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello people , i need help for calculating the size of a directory in servlet.. i am currently developing a web app where i have to upload files in folders. but what i want is that users must be only able to upload 1GB files.. if the directory has been 1GB full, then the user should not be able to upload to that folder.. I am sending my uploading servlet code , now what code should i write for calculating the directory size inside this servlet ?? Please help


i need to calculate the size in bytes so that i can place a if-else statement later for upload..
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally people consider the "size of a directory" to be the sum of the sizes of all the files in that directory. So that's what you would do.

Check out the java.io.File class; it has a method which will give you the list of the files in a directory, and it has a method which will tell you the size of a file. The summing-up I leave to you.

By the way you wouldn't write this in any special way just because it happens to be in a servlet.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact this has nothing at all to do with servlets, so it's been moved to the I/O forum.
reply
    Bookmark Topic Watch Topic
  • New Topic