Java IO stream to file operations

Source: Internet
Author: User
Tags readable

Check if the file exists

Get file path

Get File size

......

More reference Manuals

//Operations on Files//Check if the file exists//Get file path//Get File Size//whether the file is readable//whether the file is writable//....ImportJava.io.*;ImportJava.util.*; Public classindex{ Public Static voidMain (string[] args)throwsexception{File WJ=NewFile ("D:/333.ape"); //whether the exists file exists        if(Wj.exists ()) {System.out.println ("File path:" +wj.getabsolutepath ());//Read file pathSYSTEM.OUT.PRINTLN ("File Size:" +wj.length ());//Read File sizeSystem.out.println ("Readable:" +wj.canread ());//whether the file is readableSYSTEM.OUT.PRINTLN ("Whether writable:" +wj.canwrite ());//whether the file is writable        }        Else{System.out.println ("File does not exist"); }                    }}

Method Summary

 boolean canExecute()
Tests whether the application can execute the file represented by this abstract path name.
 boolean canRead()
Tests whether the application can read the file represented by this abstract pathname.
 boolean canWrite()
Tests whether the application can modify the file represented by this abstract pathname.
 int compareTo(File pathname)
Compares two abstract path names in alphabetical order.
 boolean createNewFile()
When and only if there is no file with the name specified by this abstract pathname, a new empty file is not created.
static File createTempFile(String prefix, String suffix)
Creates an empty file in the default temporary file directory, using the given prefix and suffix to generate its name.
static File createTempFile(String prefix, String suffix, File directory)
Creates a new empty file in the specified directory, using the given prefix and suffix string to generate its name.
 boolean delete()
Deletes the file or directory represented by this abstract path name.
 void deleteOnExit()
When the virtual machine terminates, the request deletes the file or directory represented by this abstract path name.
 boolean equals(Object obj)
Tests whether this abstract path name is equal to a given object.
 boolean exists()
Tests whether the file or directory represented by this abstract path name exists.
 File getAbsoluteFile()
Returns the absolute pathname form for this abstract path name.
 String getAbsolutePath()
Returns the absolute path name string for this abstract pathname.
 File getCanonicalFile()
Returns the canonical form of this abstract path name.
 String getCanonicalPath()
Returns the canonical pathname string for this abstract path name.
 long getFreeSpace()
Returns the number of unallocated bytes in the partition specified by this abstract path name.
 String getName()
Returns the name of the file or directory represented by this abstract path name.
 String getParent()
Returns the pathname string for this abstract pathname parent directory, or returns if this pathname does not specify a parent directory null .
 File getParentFile()
Returns the abstract pathname of the parent directory for this abstract pathname, or returns if the path name does not specify a parent directory null .
 String getPath()
Converts this abstract path name to a pathname string.
 long getTotalSpace()
Returns the partition size specified by this abstract path name.
 long getUsableSpace()
Returns the number of bytes available to this virtual machine on the partition specified by this abstract path name.
 int hashCode()
Computes the hash code for this abstract path name.
 boolean isAbsolute()
Tests whether this abstract path name is an absolute pathname.
 boolean isDirectory()
Tests whether the file represented by this abstract path name is a directory.
 boolean isFile()
Tests whether the file represented by this abstract path name is a standard file.
 boolean isHidden()
Tests whether the file specified by this abstract path name is a hidden file.
 long lastModified()
Returns the time of the last modification of the file represented by this abstract path name.
 long length()
Returns the length of the file represented by this abstract path name.
 String[] list()
Returns an array of strings that specify the files and directories in the directory represented by this abstract pathname.
 String[] list(FilenameFilter filter)
Returns an array of strings that specify the files and directories in the directory that this abstract path name represents to satisfy the specified filter.
 File[] listFiles()
Returns an abstract path to the an array group that represents the files in the directory represented by this abstract path name.
 File[] listFiles(FileFilter filter)
Returns an abstract path to the an array group, which represents the files and directories in the directory that this abstract path name represents for the specified filter.
 File[] listFiles(FilenameFilter filter)
Returns an abstract path to the an array group, which represents the files and directories in the directory that this abstract path name represents for the specified filter.
static File[] listRoots()
Lists the available file system roots.
 boolean mkdir()
Creates the directory specified by this abstract path name.
 boolean mkdirs()
Creates the directory specified by this abstract pathname, including all required but nonexistent parent directories.
 boolean renameTo(File dest)
Renames the file represented by this abstract path name.
 boolean setExecutable(boolean executable)
A convenient way to set this abstract path name owner to execute permissions.
 boolean setExecutable(boolean executable, boolean ownerOnly)
Sets the execution permissions for the owner or all users of this abstract pathname.
 boolean setLastModified(long time)
Sets the last modification time of the file or directory specified by this abstract path name.
 boolean setReadable(boolean readable)
A convenient way to set the Read permission for this abstract pathname owner.
 boolean setReadable(boolean readable, boolean ownerOnly)
Sets the Read permission for the owner or all users of this abstract path name.
 boolean setReadOnly()
Marks the file or directory specified by this abstract pathname so that it can be read only.
 boolean setWritable(boolean writable)
A convenient way to set this abstract pathname owner write permission.
 boolean setWritable(boolean writable, boolean ownerOnly)
Sets the write permission for the owner or all users of this abstract path name.
 String toString()
Returns the path name string for this abstract pathname.
 URI toURI()
Constructs a file: URI that represents the name of this abstract pathname.
 URL toURL()
is obsolete. This method does not automatically escape illegal characters in the URL. It is recommended that the new code convert the abstract pathname to a URL by first toURI converting it to a URI by method, and then URI.toURL reloading the URI as a URL by means of the method.

Java IO stream to file operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.