
Write a Java program that tales filename or directo;ry name from command line. If it is a vlid flename then it should display its size.If it is a valid directory name then it shouls disply the count of numer of files in that directory.

Java Check File
import java.io.*;
import java.util.*;
class CheckFile
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter file name with path: ");
String file=input.nextLine();
File f=new File(file);
if(f.isFile()){
System.out.println("Size is: "+f.length());
}
if(f.isDirectory()){
int count=0;
File list[]=f.listFiles();
for(int i=0;i<list.length;i++){
if(list[i].isFile()){
count++;
}
}
System.out.println("Number of files: "+count);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.