我创建了一个项目,通过将文件转换为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文件中删除添加的字节以使其再次起作用?