Re: FileOutputStream append issue
Dustin wrote:
Daniel
Thank you for your reply. The thing is that I cannot submit this exact
code; it is proprietary.
The example I gave though is basically all I am doing. I am taking two
files and make them byte[]. I then try to write these to a
FileOutputStream. I do the creation of the byte[] before creating the
FOS because I am trying to write them back to the destination of the
first file.
I hope this helps.
Dustin
Did you even read my message?
Give us code that recreates your problem. It doesn't have to be the
exact same code as your proprietary code, but it should suffer the same
issues.
Also, is broken code worth being proprietary? :-)
The following works for me, I'm guessing it is some other problem with
your code.
<sscce>
import java.io.*;
public class FileOutputStreamTest {
public static void main(String...args) throws IOException {
File file = new
File("net.virtualinfinity.FileOutputStreamText.dat");
file.delete();
FileOutputStream fileOutputStream = new FileOutputStream(file,
true);
fileOutputStream.write(new byte[] {1, 2, 3, 4, 5});
fileOutputStream.flush();
fileOutputStream.write(new byte[] {6, 7, 8, 9, 10});
fileOutputStream.flush();
fileOutputStream.close();
FileInputStream inputStream = new FileInputStream(file);
byte[] input = new byte[inputStream.available()];
inputStream.read(input);
if (input.length != 10) {
System.out.println("Expected 10 bytes, but got " +
input.length);
} else {
for (int i = 0; i < 10; ++i) {
if (input[i] != i + 1) {
System.out.println("Data is incorrect at location "
+ i);
}
}
}
}
}
</sscce>