Click here to watch in Youtube :
https://www.youtube.com/watch?v=FdYtSyAbpp0&list=UUhwKlOVR041tngjerWxVccw
FileDemo1.java
Outputhttps://www.youtube.com/watch?v=FdYtSyAbpp0&list=UUhwKlOVR041tngjerWxVccw
FileDemo1.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 = trueFileDemo2.java
import 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); } }Output
isDir = true
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_File_path_check_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_File_path_check_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/882ffbbbc9c8fbb765fb4869059bc3ee253ad31b/BasicJava/JavaIODemo_File_path_check_App/?at=master
See also:
No comments:
Post a Comment