Unable to use Zip File System (Java 7) in android-studio (5.0 Lollipop)

五迷三道 提交于 2021-01-29 04:50:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!