I am receiving the FileOutputStream as String in my servlet, How can I write it to file.
I tried to convert the string to bytes and than assigned it to new FileOutputStream, it generates the file but says the format is corrupted.
I tried various codes but none of them is working.
File file = new File("d:/file1.pdf");
String content = request.getParameter("TextB1");
try (FileOutputStream fop = new FileOutputStream(file)) {
// get the content in bytes
byte[] contentInBytes = content.getBytes();
fop.write(contentInBytes);
fop.flush();
fop.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}