/*program which creates a text file in your hard drive */
package file_create;
import java.io.*;
class MyFile
{
public static void main(String[] args)
{
try
{
File f;
f=new File("E://MyFile.txt");
if(!f.exists())
{
f.createNewFile();
System.out.println("File created successfully...");
}
else
System.out.println("File already exits...");
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
}
}
output
run:
File created successfully...
BUILD SUCCESSFUL (total time: 0 seconds)
After that , you check your hard drive of the system,a file exits in E:/ drive with name MyFile.txt.
package file_create;
import java.io.*;
class MyFile
{
public static void main(String[] args)
{
try
{
File f;
f=new File("E://MyFile.txt");
if(!f.exists())
{
f.createNewFile();
System.out.println("File created successfully...");
}
else
System.out.println("File already exits...");
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
}
}
output
run:
File created successfully...
BUILD SUCCESSFUL (total time: 0 seconds)
After that , you check your hard drive of the system,a file exits in E:/ drive with name MyFile.txt.
No comments:
Post a Comment