Click here to watch in Youtube :
FileDemo1.java
OutputFileDemo1.java
import java.io.File;
/*
* Check if Path is File or Directory
*/
public class FileDemo1
{
public static void main(String[] args)
{
File file = new File("D:/work/myfile.txt");
/*
* Tests whether the file denoted by this abstract
* pathname is a normal file.
*
* Returns: true if and only if the file denoted by
* this abstract pathname exists and is a normal
* file; false otherwise
*/
boolean isFile = file.isFile();
System.out.println("isFile = " + isFile);
}
}
isFile = true
FileDemo2.javaimport java.io.File;
/*
* Check if Path is File or Directory
*/
public class FileDemo2
{
public static void main(String[] args)
{
File file = new File("D:/work");
/*
* Tests whether the file denoted by this abstract
* pathname is a directory.
*
* Returns: true if and only if the file denoted by
* this abstract pathname exists and is a directory;
* false otherwise.
*/
boolean isDir = file.isDirectory();
System.out.println("isDir = " + isDir);
}
}
OutputisDir = true
No comments:
Post a Comment