-1
Part filePart = request.getPart("barcodePhtotoVen");

inputStream = filePart.getInputStream();

How to write this using outputstream to folder/file in my computer drive?

demongolem
  • 9,474
  • 36
  • 90
  • 105
Sher Ali
  • 523
  • 1
  • 4
  • 10

3 Answers3

0

Hope following code snippet help you

Update :

 OutputStream out = null;
 InputStream filecontent = null;

 try {
    out = new FileOutputStream(new File("destination_file_path"));
    filecontent = filePart.getInputStream();

    int read = 0;
    final byte[] bytes = new byte[1024];

    while ((read = filecontent.read(bytes)) != -1) {
        out.write(bytes, 0, read);
    }
} catch (FileNotFoundException f) {

} finally {
  if (out != null) {
        out.close();
    }
}

Earlier code I tested on mine system, perfectly worked. Please try mine updated code. I just tested on mine system and its working fine too.

Resources : Hope this knowledge sharing help you.

Thanks.

atiqkhaled
  • 386
  • 4
  • 19
0

Do not use an InputStream and do not use an OutputStream. Part has a write(String) method which writes the part directly to a file.

VGR
  • 40,506
  • 4
  • 48
  • 63
0

I have stored image to inputstream

No you haven't. You haven't stored the image anywhere, let alone to an input stream, which is a contradiction in terms. You need to read from the input stream and write to a disk file.

user207421
  • 305,947
  • 44
  • 307
  • 483