Java.io package provides an extensive library of classes to deal with input and output. Java provides streams as a general mechanism for dealing with data I/O.
There are three kinds of streams.
- Byte Streams
- Character Streams
- Buffered Streams
An output stream - an object that an application use to write a sequence of data, acts as a destination of data.
Entities work as output or input streams.
- An array of character or bytes.
- A file
- A pipe
- A network connection
File(String pathname)
Creates a new
File
instance by converting the given pathname string into an abstract pathname.Methods
- String getName() - Returns the name of the file, excluding directory file resides.
- String getPath() - Returns the (absolute or relative) pathname of the file.
- String getAbsolutePath() - Returns the absolute pathname string of this abstract pathname.
- Stirng getCononicalPath() - Platform-dependent. Returns the canonical form of this abstract pathname.
- String getParent() - The parent part of the pathname of this File object is returned if one exists, otherwise the null value is returned.
- boolean isAbsolute() - Whether a File object represents an absolute pathname can be determined using this method.
- long lastModified() - Returns the time that the file denoted by this abstract pathname was last modified.
- long length() - Returns the size (in bytes) of the file represented by the File object.
- boolean equals(Object obj) - This method only compares the pathnames of the File objects, and returns true if they are identical.
- boolean exists() - Return true if specified file or directory is existed.
- boolean isFile() - Return true if the object is a file.
- boolean isDirectory() - Returns true if the object is a directory.
- boolean canRead() - Returns true if the object has read access.
- boolean canWrite() - Returns true if the object has writing access.
- String[] list() - Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
- String[] list(FileNameFilter filter) - Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
1.3 Creating New Files and Directories
- boolean createNewFile() throws IOException - Creates a new, empty file named by the abstract pathname if,and only if, a file with this name does not already exist. Return value is true if the file is created, else false means file is already exists.
- boolean mkdir() - Creates the directory named by this abstract pathname.
- boolean mkdirs() - Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.
1.4 Rename Files and Directories
- boolean renameTo(File dest) - Renames the file denoted by this abstract pathname.
1.5 Deleting Files and Directories
- boolean delete() - Deletes the file or directory denoted by this abstract pathname.
No comments:
Post a Comment