Generate PDF in memory not in hard disk


How the pdf could be stored in memory; What I do not want to do is the following:

File newPdf = new File("/var/reports/genera01.pdf")

Basically I do not want to occupy space on the disk since after I get the PDF I want to print it with PrintJob , the pdf I will generate it from a jasper Reports.

asked by Heinz Keydel 05.09.2016 в 23:36

1 answer


A file must necessarily be on the hard drive. If you want it in memory, you can use an array of bytes that will be only in memory (Use ByteArrayInputStream and ByteArrayOutputStream to read and write arrangements similar to a file). The byte stream contains the contents of the file.

Both (File / ByteArray, Streams) extend from and , so they can be used to replace classes to hide the implementation of reading from a file or an array of bytes in memory.

answered by 09.09.2016 в 18:32