How to create a file -- including folders -- for a given path?

Viewed 64270

Am downloading a zip file from web. It contain folders and files. Uncompressing them using ZipInputstream and ZipEntry. Zipentry.getName gives the name of file as htm/css/aaa.htm.

So I am creating new File(zipentry.getName);

But problem it is throwing an exception: File not found. I got that it is creating subfolders htm and css.

My question is: how to create a file including its sub directories, by passing above path?

6 Answers

Java NIO API Files.createDirectories

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

Path path = Paths.get("/folder1/folder2/folder3");
Files.createDirectories(path);

Related