JAVA–FILE exists or Not !
//main method
import java.io.File;
public class A {
public static void main(String[] args) {
File xFile = new File("D:\\ONLINE\\Dropbox\\CSE - WORLD\\Java File\\tx.txt");
if(xFile.exists())
{
System.out.println(xFile.getName()+" exist");
}
else {
System.out.println("no");
}
}
}
//AnotherClass
import java.util.Formatter;
public class B {
public static void main(String[] args) {
final Formatter x;
try {
x = new Formatter("shadh.txt");
System.out.println("you create a file");
}
catch (Exception e)
{
System.out.println("you got an error");
}
}
}
No comments:
Post a Comment