Java 我想覆盖现有的zipfile

Java 我想覆盖现有的zipfile,java,zip,Java,Zip,我想覆盖现有的zip文件(这意味着我在现有的zip文件中添加了新文件),但这里显示了此错误(java.util.zip.ziperor:zip-END-header-not-found) 试试这个: 如果文件存在,则在保存新文件后将其删除 或者直接在邮政编码中添加一个文件,因为此示例您是否尝试过文件.copy(myFilePath、fileInsideZipPath、StandardCopyOption.REPLACE_EXISTING)?我尝试过上面的代码only@Aru我想在现有的zip文件

我想覆盖现有的zip文件(这意味着我在现有的zip文件中添加了新文件),但这里显示了此错误(java.util.zip.ziperor:zip-END-header-not-found)

试试这个:

如果文件存在,则在保存新文件后将其删除


或者直接在邮政编码中添加一个文件,因为此示例

您是否尝试过
文件.copy(myFilePath、fileInsideZipPath、StandardCopyOption.REPLACE_EXISTING)
?我尝试过上面的代码only@Aru我想在现有的zip文件中添加新的.txt文件
private void updateZip(String fileName, String scenarioDirectory){
        System.out.println("File Name : " +fileName);
        System.out.println("Scenario Directory : " +scenarioDirectory);
       String scenarioName ="12345";
       Path myFilePath = Paths.get(fileName);
       Path zipFilePath = Paths.get(scenarioDirectory);
       FileSystem fs;
   try {
       fs = FileSystems.newFileSystem(zipFilePath,null);
       Path fileInsideZipPath = fs.getPath(scenarioName);
       Files.copy(myFilePath, fileInsideZipPath);
       fs.close();

   } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
   }
   }