A jsp receives via POST request some base64 encoded data, splitted in chunks, that I would like to save inside a file. The problem is that the way I'm doing it just overwrites the content already inside that file.
How to fix that behaviour, in the simple and basic way possible?
This is the code:
try {
int BUFFER_SIZE = 4096;
String file = request.getParameter("TEST");
byte[] bytes = file.getBytes();
File dest = new File("/tmp/test");
InputStream fileInputStream = new ByteArrayInputStream(bytes);
OutputStream outputStream = new FileOutputStream(dest);
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
I know that the base64 decoding part is missing, I will implement it after that behaviour gets fixed