Skip to main content

Posts

Showing posts with the label java file handling

File Handling(File class-1)

File Handling:- File is a class in java present in java.io package, constructor of this class is not creating physical file, where it is used to hold the physical file if file is exist. Using file object we cannot perform read write operation. Example1:- TestFile import java.io.File; class TestFile { public static void main(String[]args) { File f=new File("abc.txt"); System.out.println(f); System.out.println("f is capable to hold file abc.txt phisical file not created"); } } Output:- C:\JAVATECH>javac TestFile.java C:\JAVATECH>java TestFile abc.txt f is capable to hold file abc.txt phisical file not created Example2:- TestFile import java.io.File; class TestFile { public static void main(String[]args) { File f=new File("abc.txt"); boolean b=f.exists(); if(b) System.out.println("file exist"); else System.out.println("file not  exist"); } } Output:- C:\JAVATECH>...