if we want to get the above 2nd result, we have to write a code like this,
import java.io.*;
public class CreateFile1{
public static void main(String[] args) throws IOException{
File f;
f=new File("myfile.txt");
if(!f.exists()){
f.createNewFile();
System.out.println("New file \"myfile.txt\" has been created to the current directory");
}
else
System.out.println("\n the file is already exists");
}
}
how to create file in some specific directory ?santhoshreddy May 25, 2011 at 11:18 AM
...Please provide some solution for that one.... Ex : i want to create file in D:\nic\some ..this directory folder
creat a java filevijay February 23, 2013 at 6:46 PM
i want to creat a java file
create file in Eclipseromeo December 4, 2011 at 7:46 PM
Thank you,
programingdaisybeniasan January 9, 2012 at 5:11 AM
i want to learn more for java program
pokemon tower defense BWtonio March 1, 2012 at 2:37 AM
love java
STVE CLASSMary Lois Dela Cruz March 2, 2012 at 7:31 AM
i love my all subject teachers and my classmate
can remove is exist checckAnup March 19, 2012 at 11:13 AM
In above code, condition if(!f.exists()) is not required, since createNewFile() API creates new file only if file with name specified does not exist
Thank you!Nikita June 29, 2012 at 12:38 AM
Wow helped a lot :D thanks
javaananthi September 20, 2012 at 11:06 AM
file & streams in java
createNew FIlemansur September 25, 2012 at 12:05 AM
it doesn't work.. It says, it needs exception
quesneeravi October 6, 2012 at 11:08 PM
the above program doesn't return the statement as you mentioned above when it compile and run the second time
codeneeravi October 6, 2012 at 11:18 PM
if we want to get the above 2nd result, we have to write a code like this, import java.io.*; public class CreateFile1{ public static void main(String[] args) throws IOException{ File f; f=new File("myfile.txt"); if(!f.exists()){ f.createNewFile(); System.out.println("New file \"myfile.txt\" has been created to the current directory"); } else System.out.println("\n the file is already exists"); } }
minecraftantonis October 14, 2012 at 9:51 PM
good
Post your Comment