dknchris
dknchris

Reputation: 498

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

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?

Upvotes: 0

Views: 528

Answers (1)

Scott Barta
Scott Barta

Reputation: 80020

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

Upvotes: 1

Related Questions