This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes java.io.IOException: There is not enough space on the disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "java.io.IOException: There is not enough space on the disk" Watch "java.io.IOException: There is not enough space on the disk" New topic
Author

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

Derek White
Greenhorn

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: 477
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

Joined: Oct 27, 2005
Posts: 19538
    
  16

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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"!


[Jess in Action][AskingGoodQuestions]
Derek White
Greenhorn

Joined: Jul 24, 2008
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.IOException: There is not enough space on the disk
 
Similar Threads
Advice on InputStream reading
Send a file to server
java.io.IOException: Cannot allocate memory
ZipOutputStream creates corrupted files when bigger than 4gb
writing data to zip file