This problem seems to occur inconsistently. We use a java applet to download a file from our website, which we temporarily store on the client machine.
Here is the code we use to save the file:
URL targetUrl = new URL(urlForFile);
InputStream content = (InputStream)targetUrl.getContent();
BufferedInputStream buffered = new BufferedInputStream(content);
File savedFile = File.createTempFile("temp",".dat");
FileOutputStream fos = new FileOutputStream(savedFile);
int letter;
while((letter = buffered.read()) != -1)
fos.write(letter);
fos.close();
Later I will try to access this file using:
ObjectInputStream keyInStream = new ObjectInputStream(new FileInputStream(savedFile));
In most cases, it works without problems, but each time we get an error:
java.io.StreamCorruptedException: invalid stream header: 0D0A0D0A
which makes me think that it is not saving the file correctly.
John doe
source
share