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

inputStream = filePart.getInputStream();

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

demongolem
  • 9,148
  • 36
  • 86
  • 104
Sher Ali
  • 523
  • 1
  • 4
  • 9

4 Answers4

0

I think this question has been asked a lot, this answer provides several options for writing an inputstream into a file:

Easy way to write contents of a Java InputStream to an OutputStream

Community
  • 1
  • 1
Alex
  • 818
  • 7
  • 15
  • 1
    If the question is a duplicate, it should not be answered. It should be marked as a duplicate. – demongolem Dec 30 '16 at 16:46
  • Do i have enough rep to mark things as duplicate? I didn't think I do. I don't know the threshold. Regardless, I thought it would be helpful to the user to at least point them in the right direction instead of telling them it's a duplicate and to google it. In the future I won't answer these types of questions until I can mark them as duplicates. – Alex Dec 30 '16 at 16:49
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
  • 376
  • 4
  • 18
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
  • 37,458
  • 4
  • 42
  • 54
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
  • 298,294
  • 41
  • 291
  • 462