Code example for FileOutputStream

Methods: close, flush

0
    public static File encrypt(PdfReader reader, File out, String password) throws IOException, DocumentException {
        return encrypt(reader, out.getPath(), password);
    } 
 
    public static File encrypt(PdfReader reader, String out, String password) throws IOException, DocumentException {
        FileOutputStream outputStream = new FileOutputStream(out);
        PdfEncryptor.encrypt(reader, outputStream, null, password.getBytes(), 0, false);
        outputStream.flush();
        outputStream.close();
        return new File(out);
    } 
 
    public static File decrypt(File file) throws IOException, DocumentException {
        PdfReader reader = null;
        try { 
            reader = new PdfReader(file.getPath());
            // if pdf is a encrypted file unencrypted 
            if (reader.isEncrypted()) {
                return decrypt(reader, FileUtils.getFilePrefix(file.getPath()) + "_decrypted.pdf");
            } else { 
                return file;