File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes There is not enough space on the disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " There is not enough space on the disk" Watch " There is not enough space on the disk" New topic
Author There is not enough space on the disk

Derek White

Joined: Jul 24, 2008
Posts: 14
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

Joined: Mar 04, 2009
Posts: 482
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

Joined: Oct 27, 2005
Posts: 19914

What is the size of the file? Are you using a FAT(32) or NTFS file system?

How To Ask Questions How To Answer Questions
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
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

Joined: Jul 08, 2003
Posts: 24189

Note that read() returns "-1" when you're at end-of-file. This line

received +=, 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"!

[Jess in Action][AskingGoodQuestions]
Derek White

Joined: Jul 24, 2008
Posts: 14

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
rocket mass heater kickstarter
subject: There is not enough space on the disk