File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.IOException: There is not enough space on the disk

 
Derek White
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write some code that recursively writes large files from a server stream to a client disk. I am having issues porting my code from C#:



It works well for a while (200MB~), but then:



It would seem that this error is thrown when there isn't enough space on the disk (obvious, right?) but I am writing to a hard drive with 230GB of free space.

Thanks for your time
 
Somnath Mallick
Ranch Hand
Posts: 482
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the space on your hard disk that's left? From the error it could be that the destination drive has less space than the size of the file!
 
Rob Spoor
Sheriff
Pie
Posts: 20369
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the size of the file? Are you using a FAT(32) or NTFS file system?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are values of 'writeIndex', 'received', 'buffer.length' and 'size' when exception is thrown ?
Add this to your code and check:
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that read() returns "-1" when you're at end-of-file. This line

received += is.read(buffer, 0, buffer.length);

is a big mistake, as it uses the return value of read without checking first for the "-1". If anything goes wrong during the transmission, this line is going to bite you.

If you look at your code, you can see that if when you get to end of file prematurely -- if the connection is dropped, or if the value of 'size' is, for some reason, incorrect -- you'll end up calling "write" with -1 as the third argument. Since -1 also looks like a large positive number (2^31), you'll proceed to call write with this large argument over and over until the disk fills up.

Always test the return value of "read"!
 
Derek White
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH LORD.

Thanks for the help everyone, I just realized I never moved the project from my SD card.

Hooray for stupid moments!

Also, thanks Ernest for preventing any future disasters
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic