0% found this document useful (0 votes)
22 views11 pages

File and It'S Method: By:-Kanani Muskan R (180283116011)

This document discusses files in Java and methods of the File class. It explains that the File class provides a way to store and represent files and directories in a program. It shows how to create a File object, create a new file by calling the createNewFile() method, and lists some common File methods like getName(), getPath(), isHidden(), lastModified(), mkdir(), mkdirs(), and renameTo() along with brief descriptions of what each method does. An example demonstrates using several of these methods.

Uploaded by

Muskan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

File and It'S Method: By:-Kanani Muskan R (180283116011)

This document discusses files in Java and methods of the File class. It explains that the File class provides a way to store and represent files and directories in a program. It shows how to create a File object, create a new file by calling the createNewFile() method, and lists some common File methods like getName(), getPath(), isHidden(), lastModified(), mkdir(), mkdirs(), and renameTo() along with brief descriptions of what each method does. An example demonstrates using several of these methods.

Uploaded by

Muskan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

FILE AND IT’S METHOD

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.

• In Java to use File ,


 Java provides in-built class called “FILE ” class.
 The Java “FILE” class can be used by importing the package

“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...

You might also like