如何从java中的zip文件中删除字节?

时间:2012-10-31 10:52:43

标签: java zip

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

1 个答案:

答案 0 :(得分:2)

如果确实想要加密您的zip文件,请查看zip4j