Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help to calculate directory size  RSS feed

 
J Das
Ranch Hand
Posts: 83
Firefox Browser Java MS IE
  • Mark post as helpful
  • send pies
  • 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..
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!