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