Header

Wednesday 4 September 2013

IGNOU BCA 4th sem Solved Assignment - What are the classes in Java available for file handling

What are the classes in Java available for file handling
Ans

 Files and directories are accessed and manipulated by the File class. The File class does not actually provide for input and output to files. It simply provides an identifier of files and directories.Note: Always remember that just because a File object is created, it does not mean there actually exists on the disk a file with the identifier held by that File object.For Defining a file in a File Class there are several types of constructors.
File Class constructors:
Constructor     Description
File(File parent, String child)  This method creates a new File instance from a parent abstract pathname and a child pathname string.
File(String pathname) This method creates a new File instance by converting the given pathname string into an abstract pathname
File(String parent, String child)          This method creates a new File instance from a parent pathname string and a child pathname string.
File(String parent, String child)          This method Creates a new File instance by converting the given file: URI into an abstract pathname.
File class methods:
Method           Description
Boolean canExecute() This method tests whether the application can execute the file denoted by this abstract pathname.
Boolean canRead()     This method tests whether the application can read the file denoted by this abstract pathname.
Boolean canWrite()     This method tests whether the application can modify the file denoted by this abstract pathname.
int compareTo (File pathname)           This method compares two abstract pathnames.
Boolean createNewFile()        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.
Boolean delete()          This method deletes the file or directory denoted by this abstract pathname.
long getFreeSpace()    This method returns the number of unallocated bytes in the partition named by this abstract path name.
String getName()        This method returns the name of the file or directory denoted by this abstract pathname.
String getParent()        This method returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
File getParentFile()     This method returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
String getPath()           This method converts this abstract pathname into a pathname string.
String toString()          This method returns the pathname string of this abstract pathname.
Boolean mkdir()          This method creates the directory named by this abstract pathname.
long getTotalSpace()   This method returns the size of the partition named by this abstract pathname.
long getUsableSpace()            This method returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.
int hashCode()            This method computes a hash code for this abstract pathname.
Boolean isAbsolute()  This method tests whether this abstract pathname is absolute.
Boolean isDirectory()  This method tests whether the file denoted by this abstract pathname is a directory.
Boolean isFile()           This method tests whether the file denoted by this abstract pathname is a normal file.
Boolean isHidden()     This method tests whether the file named by this abstract pathname is a hidden file.
long lastModified()     This method returns the time that the file denoted by this abstract pathname was last modified
long length()    This method returns the length of the file denoted by this abstract pathname.
String[] list()    This method returns an array of strings naming the files and directories in the directory denoted by this abstract pathname
String[] list(Filename Filter filter)       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.
File[] listFiles()            This method returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

No comments:

Post a Comment