2
我試圖解密使用 https://github.com/martinwithaar/Encryptor4j/blob/master/src/main/java/org/encryptor4j/util/FileEncryptor.java 以下是解密方法的一部分,我修改使用的FileInputStream得到加密文件
//the following does not work
FileInputStream fis=new FileInputStream(src);
fis.skip(83);
is = encryptor.wrapInputStream(fis);
os = new FileOutputStream(dest);
//the copy method is a default method from FileEncryptor.java
copy(is, os);
以下工作正常大文件的一部分。(我要解密整個文件,然後讀取/保存文件的一部分到另一個文件然後刪除舊的,並重新命名新一箇舊的文件名。
is = encryptor.wrapInputStream(new FileInputStream(src));
os = new FileOutputStream(dest);
copy(is, os);
FileInputStream fis=new FileInputStream(dest);
fis.skip(67);
FileOutputStream fos=new FileOutputStream(dest+".2");
copy(fis,fos);
new File(dest).delete();
new File(dest+".2").renameTo(new File(dest));
fis.close();
fos.close();
我的問題是,爲什麼在上面的代碼不能正常工作? 關於如何跳過一些字節,我跟着http://www.tutorialspoint.com/java/io/fileinputstream_skip.htm。
剛剛試過,它不跳過任何字節 – ikel
你的意思是'skip()'返回零?在這種情況下,你只需要用包裝的輸入流來閱讀它們。 – EJP
問題是文件過大(大於整數的MAX VALUE),讀到字節數組會導致內存異常 – ikel