- Java.io - Writer
- Java.io - StringWriter
- Java.io - StringReader
- Java.io - StringBufferInputStream
- Java.io - StreamTokenizer
- Java.io - SerializablePermission
- Java.io - SequenceInputStream
- Java.io - Reader
- Java.io - RandomAccessFile
- Java.io - PushbackReader
- Java.io - PushbackInputStream
- Java.io - PrintWriter
- Java.io - PrintStream
- Java.io - PipedWriter
- Java.io - PipedReader
- Java.io - PipedOutputStream
- Java.io - PipedInputStream
- Java.io - OutputStreamWriter
- Java.io - OutputStream
- Java.io - ObjectStreamField
- Java.io - ObjectStreamClass
- io - ObjectOutputStream.PutField
- Java.io - ObjectOutputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectInputStream
- Java.io - LineNumberReader
- Java.io - LineNumberInputStream
- Java.io - InputStreamReader
- Java.io - InputStream
- Java.io - FilterWriter
- Java.io - FilterReader
- Java.io - FilterOutputStream
- Java.io - FilterInputStream
- Java.io - FileWriter
- Java.io - FileReader
- Java.io - FilePermission
- Java.io - FileOutputStream
- Java.io - FileInputStream
- Java.io - FileDescriptor
- Java.io - File
- Java.io - DataOutputStream
- Java.io - DataInputStream
- Java.io - Console
- Java.io - CharArrayWriter
- Java.io - CharArrayReader
- Java.io - ByteArrayOutputStream
- Java.io - ByteArrayInputStream
- Java.io - BufferedWriter
- Java.io - BufferedReader
- Java.io - BufferedOutputStream
- Java.io - BufferedInputStream
- Java.io - Home
Java.io package extras
Java.io package Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.io.File Class
Introduction
The Java.io.File class is an abstract representation of file and directory pathnames. Following are the important points about File −
Instances may or may not denote an actual file-system object such as a file or a directory. If it does denote such an object then that object resides in a partition. A partition is an operating system-specific portion of storage for a file system.
A file system may implement restrictions to certain operations on the actual file-system object, such as reading, writing, and executing. These restrictions are collectively known as access permissions.
Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change.
Class declaration
Following is the declaration for Java.io.File class −
pubpc class File extends Object implements Seriapzable, Comparable<File>
Field
Following are the fields for Java.io.File class −
static String pathSeparator − This is the system-dependent path-separator character, represented as a string for convenience.
static char pathSeparatorChar − This is the system-dependent path-separator character.
static String separator − This is the system-dependent default name-separator character, represented as a string for convenience.
static char separatorChar − This is the system-dependent default name-separator character.
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | File(File parent, String child) This method creates a new File instance from a parent abstract pathname and a child pathname string. |
2 | File(String pathname) This method creates a new File instance by converting the given pathname string into an abstract pathname. |
3 | File(String parent, String child) This method creates a new File instance from a parent pathname string and a child pathname string. |
4 | File(URI uri) This method Creates a new File instance by converting the given file : URI into an abstract pathname. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method tests whether the apppcation can execute the file denoted by this abstract pathname. |
2 | This method tests whether the apppcation can read the file denoted by this abstract pathname. |
3 | This method tests whether the apppcation can modify the file denoted by this abstract pathname. |
4 | This method compares two abstract pathnames lexicographically. |
5 | This method atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. |
6 | This method creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. |
7 | This method Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. |
8 | This method deletes the file or directory denoted by this abstract pathname. |
9 | This method requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. |
10 | This method tests this abstract pathname for equapty with the given object. |
11 | This method tests whether the file or directory denoted by this abstract pathname exists. |
12 | This method returns the absolute form of this abstract pathname. |
13 | This method returns the absolute pathname string of this abstract pathname. |
14 | This method returns the canonical form of this abstract pathname. |
15 | This method returns the canonical pathname string of this abstract pathname. |
16 | This method returns the number of unallocated bytes in the partition named by this abstract path name. |
17 | This method returns the name of the file or directory denoted by this abstract pathname. |
18 | This method returns the pathname string of this abstract pathname s parent, or null if this pathname does not name a parent directory. |
19 | This method returns the abstract pathname of this abstract pathname s parent, or null if this pathname does not name a parent directory. |
20 | This method converts this abstract pathname into a pathname string. |
21 | This method returns the size of the partition named by this abstract pathname. |
22 | This method returns the number of bytes available to this virtual machine on the partition named by this abstract pathname. |
23 | This method computes a hash code for this abstract pathname. |
24 | This method tests whether this abstract pathname is absolute. |
25 | This method tests whether the file denoted by this abstract pathname is a directory. |
26 | This method tests whether the file denoted by this abstract pathname is a normal file. |
27 | This method tests whether the file named by this abstract pathname is a hidden file. |
28 | This method returns the time that the file denoted by this abstract pathname was last modified. |
29 | This method returns the length of the file denoted by this abstract pathname. |
30 | This method returns an array of strings naming the files and directories in the directory denoted by this abstract pathname. |
31 | This method returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. |
32 | This method returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. |
33 | This method returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. |
34 | This method returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. |
35 | This method psts the available filesystem roots. |
36 | This method creates the directory named by this abstract pathname. |
37 | This method creates the directory named by this abstract pathname, including any necessary but non existent parent directories. |
38 | This method renames the file denoted by this abstract pathname. |
39 | This is a convenience method to set the owner s execute permission for this abstract pathname. |
40 | This method Sets the owner s or everybody s execute permission for this abstract pathname. |
41 | This method sets the last-modified time of the file or directory named by this abstract pathname. |
42 | This is a convenience method to set the owner s read permission for this abstract pathname. |
43 | This method sets the owner s or everybody s read permission for this abstract pathname. |
44 | This method marks the file or directory named by this abstract pathname so that only read operations are allowed. |
45 | This is a convenience method to set the owner s write permission for this abstract pathname. |
46 | This method sets the owner s or everybody s write permission for this abstract pathname. |
47 | This method returns the pathname string of this abstract pathname. |
48 | This method constructs a file : URI that represents this abstract pathname. |
Methods inherited
This class inherits methods from the following classes −
Java.io.Object