Professional Documents
Culture Documents
File and It'S Method: By:-Kanani Muskan R (180283116011)
File and It'S Method: By:-Kanani Muskan R (180283116011)
By:-
Kanani Muskan R (180283116011)
Introduction:-
• What is File??
• We can say a file provide a way to store data,some information,
settings or commands in a computer.
“import java.io.File;”
or
“import java.io.*;”
How to create a File?
• A file can be created by creating object of the in-built “File”
class in java.
Syntax:-
File fp=new File(“file1.txt”);
• Here fp is a object to File class and “file1.txt” is a name of
the file to be created.
2nd Step:-
fp.createNewFile();
• In Java the first step only intitalize the creation of the file.
• For actual creation we need to call the method
“createNewFile()” of File class.
Example :-
Output:-
File Methods:-
No Syntax Description
1 getName() Returns the name of the file or directory
denoted by this abstract pathname
2 getPath() Converts this abstract pathname into a pathname
string.
3 getAbsolutePath() Returns the absolute pathname string of this
abstract pathname.
4 isHidden() Tests whether the file named by this abstract
pathname is a hidden file.
5 lastModified() Returns the time that the file denoted by this
abstract pathname was last modified.
6 mkdir() Creates the directory named by this abstract
pathname.
7 mkdirs() Creates the directory named by this abstract
pathname, including any necessary but
nonexistent parent directories.
8 renameTo() Renames the file denoted by this abstract
pathname.
Example:-
Output:-
Thank You...