使用lock()java编写文件

时间:2014-09-15 15:52:24

标签: java pdf locking pdfbox fileoutputstream

我正在使用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();
            }

0 个答案:

没有答案