How to create a directory in "user.home"?

How to create a directory inside the user's home?

I know how to create a regular directory, but how do you set the path for it using user.home ?

+4
source share
2 answers
 boolean success = new java.io.File(System.getProperty("user.home"), "directory_name").mkdirs(); 
+11
source

Properties of the system

Improving the response to the message! collected all the information and gathered it together.

 public static void main(String[] args) { String myDirectory = "Yash"; // user Folder Name String path = getUsersHomeDir() + File.separator + myDirectory ; if (new File(path).mkdir()) { System.out.println("Directory is created!"); }else{ System.out.println("Failed to create directory!"); } getOSInfo(); } public static void getOSInfo(){ String os = System.getProperty("os.name"); String osbitVersion = System.getProperty("os.arch"); String jvmbitVersion = System.getProperty("sun.arch.data.model"); System.out.println(os + " : "+osbitVersion+" : "+jvmbitVersion); } public static String getUsersHomeDir() { String users_home = System.getProperty("user.home"); return users_home.replace("\\", "/"); // to support all platforms. } 

To print all available properties.

 for (Entry<Object, Object> e : System.getProperties().entrySet()) { System.out.println(String.format("%s = %s", e.getKey(), e.getValue())); } 
+1
source

Source: https://habr.com/ru/post/1389181/


All Articles