我想用相同名称的外部文件替换prj-basics-final.zip中的特定文件(README.MD)。 下面的代码不会替代prj-basics-final.zip中的README.MD。它也不会引发任何错误。
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class UpdateZipFile {
public static void main(String[] args) {
Path zipFilePath = Paths.get("/Users/pradeepjonnalagadda/ZipFile/prj-basics-final.zip");
Path externalFile = Paths.get("/Users/pradeepjonnalagadda/ZipFile/README.md");;
try {
FileSystem fs = FileSystems.newFileSystem(zipFilePath, null);
Path fileInsideZipPath = fs.getPath("/README.md");
Files.copy(externalFile, fileInsideZipPath,StandardCopyOption.REPLACE_EXISTING);
System.out.println("Finished processing");
} catch (IOException e) {
e.printStackTrace();
}
}
}