Java determines whether a folder, file exists, or creates a folder 2012-07-02 23:35:08
Category: Java
1, determine whether the file exists, does not exist to create a file
[Java]View Plaincopyprint?
- File file=new file ("c:\\users\\qping\\desktop\\javascript\\2.htm");
- if (!file.exists ())
- {
- try {
- File.createnewfile ();
- } catch (IOException e) {
- //TODO auto-generated catch block
- E.printstacktrace ();
- }
- }
2, determine whether the folder exists, does not exist create folder
[Java]View Plaincopyprint?
- File File =new file ("C:\\users\\qping\\desktop\\javascript");
- If the folder does not exist, create
- if (!file. Exists () &&!file. Isdirectory ())
- {
- System.out.println ("//Not Present");
- File. mkdir ();
- } Else
- {
- System.out.println ("//Directory Exists");
- }
- Http://blog.chinaunix.net/uid-26284395-id-3260936.html
Java determines if a folder, file exists, or creates a folder