我制作了一个项目来加密文件,方法是将其转换为 zip 文件,然后向其中添加一个字节数组。
添加后点击文件时,返回“损坏的文件”。
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
public class TestByteSyt {
byte[] data;
public void choos(String path){
try{
data=getBytesContent(path);}catch(Exception e){
System.out.print("there is problem");
}
}
public byte[] getBytesContent(String path){
byte[] filedata = null;
try{
File file = new File(path);
filedata = new byte[(int)file.length()];
FileInputStream input = new FileInputStream(file);
FileOutputStream output= new FileOutputStream(file);
//input.read(filedata);
String pass="the password is sobhi saede";
byte[] b=pass.getBytes();
System.out.print(b);
output.write(b);
input.close();
output.close();
// System.out.print( file.delete());
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.close();
} catch (Exception e)
{System.out.print("no file ");}
return filedata;
}}
如何从 zip 文件中删除添加的字节以使其再次工作?