无法在android-studio(5.0 Lollipop)中使用Zip文件系统(Java 7)

问题描述:

我一直试图在不提取zip的情况下替换zip中的文件.我尝试在此处使用最有效的答案: https://*.com/a/17504151/3397618

I've been trying to replace a file in zip without extracting the zip. I tried using the most efficient answer here: https://*.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引发错误,提示:错误:找不到符号变量路径,错误:找不到符号方法toUri(),错误:找不到符号类FileSystem,错误:找不到符号变量FileSystems.

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.

Android是否不完全支持Java 7?还是我需要做一些事情才能使其正常工作?

Is it that android doesn't support Java 7 entirely?? Or do I need to do something to get it working?

Android具有自己的Java库类实现,并且不完全支持Oracle库中的所有内容. java.nio.file.Path 类不在Android的实现中.

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.

您可以在nio 包中可用内容的文档.="nofollow"> http://developer.android.com/reference/java/nio/package-summary.html

You can see documentation on what's available in Android's nio package at http://developer.android.com/reference/java/nio/package-summary.html