First Example of File Handling in Java

Updated:13/feb/2020 by Computer Hope

File handling is very usefull module for learning effective prgraming.
There are some important method that is very common :--
Load a file from local system :new File("D:/Assignments/Test Papers/Test Paper 1.docx")
file exist in local or not :exists()
printing file Name :myfile.getName()
checking file is hidden :myfile.isHidden()

import java.io.*;
class FileExample1
{
	public static void main(String args[]) 
{
    File myfile=new File("D:/Assignments/Test Papers/Test Paper 1.docx");
    if(myfile.exists())
    {
    	System.out.println(myfile.getName() +" is present");
    }
    else
    {
    	System.out.println("File not present");
    	System.exit(0);
    }
    if(myfile.isFile())
    {
    	System.out.println(myfile.getName()  +" is a file");
    }
    else
    {
    	System.out.println(myfile.getName()  +" is a directory");
    	
    }
    if(myfile.isHidden())
    {
    	System.out.println(myfile.getName()  +" is hidden");
    }
    else
    {
    	System.out.println(myfile.getName()  +" not hidden");
    	
    }
}
}