// Author: [email] huapingsmith@hotmail.com [/Email]
// Description: Check whether the folder exists. If the folder does not exist, create one. If yes, continue running.
// After the folder is processed, the next step is to create a file in the folder.
// Caution: When a file named abc.txt already exists in the prefix folder,
// Creating a file named abc.txt in front of the folder will fail.
// In this program, if the file E: // test is named 1, 2, 3, and 4, the program will fail to be executed.
Import java. Io .*;
Public class demo
{
Public static void main (string [] ARGs)
{
File dirfile;
File tempfile;
Boolean bfile;
String sfilename;
Bfile = false;
Try
{
Dirfile = new file ("E: // test ");
Bfile = dirfile. exists ();
If (bfile = true)
{
System. Out. println ("the folder exists .");
}
Else
{
System. Out. println ("the folder do not exist, now trying to create a one ...");
Bfile = dirfile. mkdir ();
If (bfile = true)
{
System. Out. println ("create successfully! ");
}
Else
{
System. Out. println ("Disable to make the folder, please check the disk is full or not .");
System. Exit (1 );
}
}
System. Out. println ("now we put files in to the folder ...");
For (INT I = 0; I <5; I ++)
{
Sfilename = new string ("E: // test //");
Sfilename + = string. valueof (I );
Tempfile = new file (sfilename );
Bfile = tempfile. createnewfile ();
}
} Catch (ioexception E)
{
// Exception hadler
}
If (bfile = true)
System. Out. println ("successfully put files in to the folder! ");
Else
System. Out. println ("sorry sir, I don't finish the job! ");
}
}