FileDemo1.java
Outputimport java.io.File;
/*
*Once you have instantiated a File object we can check
*if the corresponding file/dir actually exists already.
*/
public class FileDemo1
{
public static void main(String[] args)
{
File file = new File("D:/work/myfile.txt");
/*
* Tests whether the file or directory denoted by
* this abstract pathname exists.
*/
boolean isExist = file.exists();
System.out.println(file.getAbsolutePath() + " is exist? = " + isExist);
}
}
D:\work\myfile.txt is exist? = true
FileDemo2.javaimport java.io.File;
/*
*Once you have instantiated a File object we can check
*if the corresponding file/dir actually exists already.
*/
public class FileDemo2
{
public static void main(String[] args)
{
File file = new File("D:/work/");
/*
* Tests whether the file or directory denoted by
* this abstract pathname exists.
*/
boolean isExist = file.exists();
System.out.println(file.getAbsolutePath() + " is exist? = " + isExist);
}
}
D:\work is exist? = true
No comments:
Post a Comment