Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of java folder Operation

Shulou Source: shulou.com Published: 2022-06-01 04:34:59 09月11日 Update

This article shares with you the content of a sample analysis of java folder operations. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Folder operation

Package com.file;import java.io.File;/** * Created by elijahliu on 2017-2-11. * / public class HelloFolder {public static void main (String [] args) {File folder = new File ("my newfolder"); if (folder.mkdir ()) {/ / create a folder to determine whether System.out.println is successful ("folder creation completed"); File newfolder = new File ("myn new foleder-new") Folder.renameTo (newfolder); / / the folder renamed here can change the folder name at one level separately, while the folder below this level keeps the directory structure if (folder.delete ()) {System.out.print ("done"). / the deletion here can only delete an empty folder. If there is something in the folder, it cannot be deleted. Directly deleting a non-empty folder without asking is very irresponsible} else {System.out.println ("fail");}} else {if (folder.exists ()) {System.out.println ("folder already exists without creating") } else {System.out.println ("folder creation failed");} File folders = new File ("my new folder/one/two/three/main"); folders.mkdirs (); / / you can only create one with mkdir in java, and mkdirs can create multi-level directories}} thank you for reading! This is the end of this article on "sample Analysis of java folder Operation". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Files folders examples analysis content more directories articles good practical successful not used things in use articles look knowledge structure responsibility face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Shulou Technology Shulou Tech Info MariaDB