Open the "byte array file" from the Java applet

I have a signed applet that extracts a PDF from a web service, then saves it in the temp folder and opens it in Adobe Reader. I would like to avoid storing the file locally, but I really don't know how to achieve it (I'm new to Java applets).

If it was a web application (i.e. a simple servlet), I could just write the PDF content by ServletResponse; then the browser will save it in its temporary folder and open it using Adobe Reader (or any other application associated with the MIME type).

Is there a similar way to do this ... on a Java applet?

This is my code:

public class MyListener implements ActionListener {
    public void actionPerformed(ActionEvent event) {
        // Retrieve the document contents
        byte[] content = webService.getPdfDocument(...);

        // Write to file
        File f = new File("my-document-filename.pdf");
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(content);
        fos.close();

        // Open the file
        Desktop.getDesktop().open(new File("my-document-filename.pdf"));
    }
}

Any alternative to Desktop.open (File) allowing me to pass in byte[]instead File?

+5
1
  • Adobe reader URL: s, (?) URL- .

  • , File.createTempFile, API:

    , , . , , :

    • , , ,
    • , .

    . , , deleteOnExit().

    , :

    File f = File.createTempFile("tmp", ".pdf");
    f.deleteOnExit(); // deletes the file on exit
    ...
    
+2

All Articles