Code
---------------
import java.io.File;
class CheckFile {
public static void main(String args[]) {
File file = new File("C:/java");
// Way-1
if (file.isDirectory())
System.out.println(file.getName() + " is a directory");
else
System.out.println(file.getName() + " is a file");
// Way-2
if (file.isFile())
System.out.println(file.getName() + " is a file");
else
System.out.println(file.getName() + " is a directory");
}
}
---------------
import java.io.File;
class CheckFile {
public static void main(String args[]) {
File file = new File("C:/java");
// Way-1
if (file.isDirectory())
System.out.println(file.getName() + " is a directory");
else
System.out.println(file.getName() + " is a file");
// Way-2
if (file.isFile())
System.out.println(file.getName() + " is a file");
else
System.out.println(file.getName() + " is a directory");
}
}
Sample Output
------------------
java is a directory
java is a directory
No comments:
Post a Comment