title: Convert byte[] to PDF file without saving in local disk in Java
body: <p>I am taking byte array as input and it should convert to PDF type file without writing into local system and this is my code:</p>
  <pre class="lang-java prettyprint-override"><code>public File convertToFile(byte[] data) throws IOException, NullPointerException {
          
          FileOutputStream bar = null;
          String pathname = &quot;filename.pdf&quot;;
          File file = new File(pathname);
          try (ByteArrayInputStream bais = new ByteArrayInputStream(data);
              ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length)) {
              bar = new FileOutputStream(file);
              int c = 0;
              while (c &lt; bais.read()) {
                  baos.write(data);
                  baos.writeTo(bar);``
                  baos.flush();
              }
          } catch (Exception e) {
              e.getMessage();
          }
          return file;
      }
  </code></pre>
  <p>When I run this code it is returning my local path.</p>