Java file mkdirs


 

Java file mkdirs

This section demonstrates you the use of method mkdirs().

This section demonstrates you the use of method mkdirs().

Java file mkdirs

This section demonstrates you the use of method mkdirs().

Explanation:

The File class in java.io package works with both files and directories. This class provides many useful functions for operating the files and directories. Here we will discuss the function mkdirs().

The method mkdirs() actually creates directory structures. It creates the directory named by the abstract pathname, including any necessary but nonexistent parent directories. In the given code, we have specified C:/Hello/Java/File, so it will first create the non existent parent directories "C:/Hello", then "C:/Hello/Java", and then finally create our directory "C:/Hello/Java/File".

Here is the code:

import java.io.*;

public class FileMkdirs {
	public static void main(String[] args) {
		File f = new File("C:/Hello/Java/File");
		f.mkdirs();
	}
}

Ads