在不解壓縮的情況下修改壓縮包內的檔案
FileSystem fileSystem; try { fileSystem = FileSystems.newFileSystem(path2File.toPath(), null);//path2File是壓縮包的File Path zipXmlPath =fileSystem.getPath("/description.xml"); //獲取壓縮包內xml的path String description1= path2File.getParent()+"/description1.xml"; File description1File = new File(description1); if(!description1File.exists()){ description1File.createNewFile();//此檔案用來存放從的description.xml複製的內容 } Path dPath1 =description1File.toPath(); Files.copy(zipXmlPath,dPath1, StandardCopyOption.REPLACE_EXISTING);//將壓縮檔案的description.xml複製內容到description1.xml檔案中 String modifyXml= path2File.getParent()+"/description.xml"; File modifyFile = new File(modifyXml); if(!modifyFile.exists()){ modifyFile.createNewFile();//此檔案用來存放description1.xml修改後的內容 } Path modifyPath =modifyFile.toPath(); BufferedReader reader = Files.newBufferedReader(dPath1, StandardCharsets.UTF_8); BufferedWriter writer = Files.newBufferedWriter(modifyPath, StandardCharsets.UTF_8); String str = null; boolean flag=true; while ((str = reader.readLine()) != null) { writer.write(str); writer.write("\r\n"); } writer.flush(); writer.close(); Files.copy(modifyPath,zipXmlPath, StandardCopyOption.REPLACE_EXISTING); //將修改後的檔案再複製到壓縮檔案內