Slip No 23 Q A

Q.Write a java program to check whether given file is hidden or not. If not then display its path, otherwise display appropriate message. [15 M]

import java.io.*;
import java.util.Scanner;

class CheckHiddenFile
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter file name: ");
        String fname = sc.nextLine();

        File f = new File(fname);

        if(f.exists())
        {
            if(f.isHidden())
            {
                System.out.println("File is hidden.");
            }
            else
            {
                System.out.println("File is not hidden.");
                System.out.println("File Path: " + f.getAbsolutePath());
            }
        }
        else
        {
            System.out.println("File does not exist.");
        }
    }
}
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top