问题
I've been trying to replace a file in zip without extracting the zip. I tried using the most efficient answer here: https://stackoverflow.com/a/17504151/3397618
I'll paste the code below for reference however.
Map<String, String> env = new HashMap<>();
env.put("create", "true");
Path path = Paths.get("test.zip");
URI uri = URI.create("jar:" + path.toUri());
try (FileSystem fs = FileSystems.newFileSystem(uri, env))
{
Path nf = fs.getPath("new.txt");
try (Writer writer = Files.newBufferedWriter(nf, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) {
writer.write("hello");
}
}
Android Studio throws an error saying: error: cannot find symbol variable Paths, error: cannot find symbol method toUri(), error: cannot find symbol class FileSystem, error: cannot find symbol variable FileSystems.
Is it that android doesn't support Java 7 entirely?? Or do I need to do something to get it working?
回答1:
Android has its own implementations of the Java library classes, and it doesn't have full support for everything that's in Oracle's libraries. The java.nio.file.Path
class isn't in Android's implementation.
You can see documentation on what's available in Android's nio
package at http://developer.android.com/reference/java/nio/package-summary.html
来源:https://stackoverflow.com/questions/28339538/unable-to-use-zip-file-system-java-7-in-android-studio-5-0-lollipop