我正在使用PDFbox尝试写一个现有的空pdf。我是新手使用lock()并且无法弄清楚如何写入该实例中的文件,因此我可以将信息写入其中。我想我需要一个ByteStream,但无法弄清楚如何使用它。
File pdfexport = new File(filename);
FileChannel channel = new RandomAccessFile(pdfexport, "rw").getChannel();
if (pdfexport.exists()) {
FileLock lock = channel.lock();
FileOutputStream fop = new FileOutputStream(channel.write());
//The above line says there is an error which there probably is.
documentnew.save(fop);
lock.release();
channel.close();
}