Empty file?


#1

Hi,

Maybe I’m tired, but I can’t figure out why this code creates an empty file :

		[code]// At this point, we have a someString object of type juce::String which is correctly filled, according to the debugger.
		juce::OutputStream* os=someFile.createOutputStream();
		os->writeString(someString);
		os->flush();
		delete os;[/code]

The file object (someFile), is created, at the right place, but…it’s empty. The string “smeString” is not empty though. No idea why it happens. Any clues ?


#2
FileOutputStream * 	createOutputStream (int bufferSize=0x8000) const 

The method returns FileOutputStream. You should ideally try

bool 	write (const void *data, int numBytes)

#3

I suspect that the file is not empty at all, but you may not have properly read the comments about exactly what writeString() should be used for…?


#4

True, I should have used writeText instead. However, I tried it and …same result : 0 bytes file ! :o
I also tried File::appendText , File::replaceWithText with the same result too. Can you see any reason why this would happen ? The weirdest thing is that those functions return true, indicating success !

  • Can this be a cache problem (but I call flush and delete) ?
  • Can it be that juce faills to copy from a temp file to the actual file ?

#5

It’s more likely that you’re not actually writing to the file that you think you are. Print out the file name to check it, and step through it in your debugger to see what’s happening - chances are that it’ll be a simple mistake.