Java Doc for File.java in  » Apache-Harmony-Java-SE » java-package » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.io.File

File
public class File implements Serializable,Comparable<File>(Code)
File is a class which represents a file name or directory. The file may be absolute relative to the root directory of the file system or relative to the current directory in which the program is running.

This class provides methods for querying/changing information about the file and also directory listing capabilities if the File represents a directory.

When manipulating file paths, the static fields of this class may be used to determine the platform specific separators.
See Also:   java.io.Serializable
See Also:   java.lang.Comparable



Field Summary
final public static  StringpathSeparator
     System dependent path separator String.
final public static  charpathSeparatorChar
     System dependent path separator character.
transient  byte[]properPath
    
final public static  Stringseparator
     System dependent file separator String.
final public static  charseparatorChar
     System dependent file separator character.

Constructor Summary
public  File(File dir, String name)
     Constructs a new File using the specified directory and name.
public  File(String path)
     Constructs a new File using the specified path.
public  File(String dirPath, String name)
     Constructs a new File using the specified directory and name placing a path separator between the two.
public  File(URI uri)
     Constructs a new File using the path of the specified URI uri needs to be an absolute and hierarchical URI with file scheme, and non-empty path component, but with undefined authority, query or fragment components.

Method Summary
public  booleancanRead()
     Answers a boolean indicating whether or not the current context is allowed to read this File.
public  booleancanWrite()
     Answers a boolean indicating whether or not the current context is allowed to write to this File.
public  intcompareTo(File another)
     Answers the relative sort ordering of paths for the receiver and given argument.
public  booleancreateNewFile()
     Creates the file specified by this File.
public static  FilecreateTempFile(String prefix, String suffix)
     Creates an empty temporary file using the given prefix and suffix as part of the file name.
public static  FilecreateTempFile(String prefix, String suffix, File directory)
     Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.
public  booleandelete()
     Deletes the file specified by this File.
public  voiddeleteOnExit()
     When the virtual machine terminates, any abstract files which have been sent deleteOnExit() will be deleted.
public  booleanequals(Object obj)
     Compares the argument obj to the receiver, and answers true if they represent the same object using a path specific comparison.
public  booleanexists()
     Answers a boolean indicating whether or not this File can be found on the underlying file system.
public  FilegetAbsoluteFile()
     Answers a new File constructed using the absolute file path of this File.
public  StringgetAbsolutePath()
     Answers the absolute file path of this File.
public  FilegetCanonicalFile()
     Answers a new File created using the canonical file path of this File.
public  StringgetCanonicalPath()
     Answers the absolute file path of this File with all references resolved. An absolute file path is one which begins at the root of the file system.
public  StringgetName()
     Answers the filename (not directory) of this File.
public  StringgetParent()
     Answers the pathname of the parent of this File.
public  FilegetParentFile()
     Answers a new File made from the pathname of the parent of this File. This is the path up to but not including the last name.
public  StringgetPath()
     Answers the file path of this File.
public  inthashCode()
     Answers an integer hash code for the receiver.
public  booleanisAbsolute()
     Answers if this File is an absolute pathname.
public  booleanisDirectory()
     Answers if this File represents a directory on the underlying file system.
public  booleanisFile()
     Answers if this File represents a file on the underlying file system.
public  booleanisHidden()
     Returns whether or not this file is a hidden file as defined by the operating system.
public  longlastModified()
     Answers the time this File was last modified.
public  longlength()
     Answers the length of this File in bytes.
public  java.lang.String[]list()
     Answers an array of Strings representing the file names in the directory represented by this File.
public  java.lang.String[]list(FilenameFilter filter)
     Answers an array of Strings representing the file names in the directory represented by this File that match a specific filter.
public  File[]listFiles()
     Answers an array of Files representing the file names in the directory represented by this File.
public  File[]listFiles(FilenameFilter filter)
     Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.
public  File[]listFiles(FileFilter filter)
     Answers an array of Files representing the file names in the directory represented by this File that match a specific filter.
public static  File[]listRoots()
     Lists the filesystem roots. The Java platform may support zero or more filesystems, each with its own platform-dependent root.
public  booleanmkdir()
     Creates the directory named by the trailing filename of this File.
public  booleanmkdirs()
     Create all the directories needed for this File.
 byte[]properPath(boolean internal)
     Answer a String representing the proper path for the receiver.
public  booleanrenameTo(java.io.File dest)
     Renames this File to the name represented by the File dest. This works for both normal files and directories.
Parameters:
  dest - the File containing the new name.
public  booleansetLastModified(long time)
     Sets the time this File was last modified.
Parameters:
  time - The time to set the file as last modified.
public  booleansetReadOnly()
     Marks this file or directory to be read-only as defined by the operating system.
public  StringtoString()
     Answers a string containing a concise, human-readable description of the receiver.
public  URItoURI()
     Answers a file URI for this File.
public  URLtoURL()
     Answers a file URL for this File.

Field Detail
pathSeparator
final public static String pathSeparator(Code)
System dependent path separator String. The initial value of this field is the System property "path.separator".



pathSeparatorChar
final public static char pathSeparatorChar(Code)
System dependent path separator character.



properPath
transient byte[] properPath(Code)



separator
final public static String separator(Code)
System dependent file separator String. The initial value of this field is the System property "file.separator".



separatorChar
final public static char separatorChar(Code)
System dependent file separator character.




Constructor Detail
File
public File(File dir, String name)(Code)
Constructs a new File using the specified directory and name.
Parameters:
  dir - the directory for the file name
Parameters:
  name - the file name to be contained in the dir



File
public File(String path)(Code)
Constructs a new File using the specified path.
Parameters:
  path - the path to be used for the file



File
public File(String dirPath, String name)(Code)
Constructs a new File using the specified directory and name placing a path separator between the two.
Parameters:
  dirPath - the directory for the file name
Parameters:
  name - the file name to be contained in the dir



File
public File(URI uri)(Code)
Constructs a new File using the path of the specified URI uri needs to be an absolute and hierarchical URI with file scheme, and non-empty path component, but with undefined authority, query or fragment components.
Parameters:
  uri - the URI instance which will be used to construct this file
throws:
  IllegalArgumentException - if uri does not comply with the conditionsabove.
See Also:   File.toURI
See Also:   java.net.URI




Method Detail
canRead
public boolean canRead()(Code)
Answers a boolean indicating whether or not the current context is allowed to read this File. true if this File can be read, falseotherwise.
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



canWrite
public boolean canWrite()(Code)
Answers a boolean indicating whether or not the current context is allowed to write to this File. true if this File can be written,false otherwise.
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



compareTo
public int compareTo(File another)(Code)
Answers the relative sort ordering of paths for the receiver and given argument. The ordering is platform dependent.
Parameters:
  another - a File to compare the receiver to an int determined by comparing the two paths. The meaning isdescribed in the Comparable interface.
See Also:   Comparable



createNewFile
public boolean createNewFile() throws IOException(Code)
Creates the file specified by this File. If the file already exists this method returns false. Otherwise, if the file is created successfully, the result is true. An IOException will be thrown if the directory to contain this file does not exist. true if this File was created, falseotherwise.
throws:
  IOException - if an I/O error occurs or the directory does not exist.
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException(Code)
Creates an empty temporary file using the given prefix and suffix as part of the file name. If suffix is null, .tmp is used.
Parameters:
  prefix - the prefix to the temp file name
Parameters:
  suffix - the suffix to the temp file name the temporary file
throws:
  IOException - If an error occurs when writing the file



createTempFile
public static File createTempFile(String prefix, String suffix, File directory) throws IOException(Code)
Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.
Parameters:
  prefix - the prefix to the temp file name
Parameters:
  suffix - the suffix to the temp file name
Parameters:
  directory - the location to which the temp file is to be written, or nullfor the default temp location the temporary file
throws:
  IOException - If an error occurs when writing the file



delete
public boolean delete()(Code)
Deletes the file specified by this File. Directories must be empty before they will be deleted. true if this File was deleted, falseotherwise.
See Also:   java.lang.SecurityManager.checkDelete



deleteOnExit
public void deleteOnExit()(Code)
When the virtual machine terminates, any abstract files which have been sent deleteOnExit() will be deleted. This will only happen when the virtual machine terminates normally as described by the Java Language Specification section 12.9.



equals
public boolean equals(Object obj)(Code)
Compares the argument obj to the receiver, and answers true if they represent the same object using a path specific comparison.
Parameters:
  obj - the Object to compare with this Object true if the object is the same as this object,false otherwise.



exists
public boolean exists()(Code)
Answers a boolean indicating whether or not this File can be found on the underlying file system. true if this File exists, falseotherwise.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



getAbsoluteFile
public File getAbsoluteFile()(Code)
Answers a new File constructed using the absolute file path of this File. a new File from this absolute file path
See Also:   java.lang.SecurityManager.checkPropertyAccess



getAbsolutePath
public String getAbsolutePath()(Code)
Answers the absolute file path of this File. the absolute file path
See Also:   java.lang.SecurityManager.checkPropertyAccess



getCanonicalFile
public File getCanonicalFile() throws IOException(Code)
Answers a new File created using the canonical file path of this File. Equivalent to new File(this.getCanonicalPath()). the canonical file path
throws:
  IOException - If an IO error occurs
See Also:   java.lang.SecurityManager.checkPropertyAccess



getCanonicalPath
public String getCanonicalPath() throws IOException(Code)
Answers the absolute file path of this File with all references resolved. An absolute file path is one which begins at the root of the file system. The canonical path is one in which all references have been resolved. For the cases of '..' and '.' where the file system supports parent and working directory respectively, these should be removed and replaced with a direct directory reference. If the File does not exist, getCanonicalPath() may not resolve any references and simply return an absolute path name or throw an IOException. the canonical file path
throws:
  IOException - if an IO error occurs
See Also:   java.lang.SecurityManager.checkPropertyAccess



getName
public String getName()(Code)
Answers the filename (not directory) of this File. the filename or empty string



getParent
public String getParent()(Code)
Answers the pathname of the parent of this File. This is the path up to but not including the last name. null is returned when there is no parent. the parent name or null



getParentFile
public File getParentFile()(Code)
Answers a new File made from the pathname of the parent of this File. This is the path up to but not including the last name. null is returned when there is no parent. a new File representing parent or null



getPath
public String getPath()(Code)
Answers the file path of this File. the file path



hashCode
public int hashCode()(Code)
Answers an integer hash code for the receiver. Any two objects which answer true when passed to equals must answer the same value for this method. the receiver's hash
See Also:   File.equals



isAbsolute
public boolean isAbsolute()(Code)
Answers if this File is an absolute pathname. Whether a pathname is absolute is platform specific. On UNIX it is if the path starts with the character '/', on Windows it is absolute if either it starts with '\', '/', '\\' (to represent a file server), or a letter followed by a colon. true if this File is absolute, falseotherwise.
See Also:   File.getPath



isDirectory
public boolean isDirectory()(Code)
Answers if this File represents a directory on the underlying file system. true if this File is a directory,false otherwise.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



isFile
public boolean isFile()(Code)
Answers if this File represents a file on the underlying file system. true if this File is a file, falseotherwise.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



isHidden
public boolean isHidden()(Code)
Returns whether or not this file is a hidden file as defined by the operating system. true if the file is hidden, falseotherwise.



lastModified
public long lastModified()(Code)
Answers the time this File was last modified. the time this File was last modified.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



length
public long length()(Code)
Answers the length of this File in bytes. the number of bytes in the file.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)



list
public java.lang.String[] list()(Code)
Answers an array of Strings representing the file names in the directory represented by this File. If this File is not a directory the result is null.

The entries . and .. representing current directory and parent directory are not returned as part of the list. an array of Strings or null.
See Also:   File.getPath
See Also:   File.isDirectory
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)




list
public java.lang.String[] list(FilenameFilter filter)(Code)
Answers an array of Strings representing the file names in the directory represented by this File that match a specific filter. If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.
Parameters:
  filter - the filter to match names to or null. an array of Strings or null.
See Also:   File.getPath
See Also:   File.isDirectory
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)




listFiles
public File[] listFiles()(Code)
Answers an array of Files representing the file names in the directory represented by this File. If this File is not a directory the result is null. The Files returned will be absolute if this File is absolute, relative otherwise. an array of Files or null.
See Also:   File.getPath
See Also:   File.list()
See Also:   File.isDirectory



listFiles
public File[] listFiles(FilenameFilter filter)(Code)
Answers an array of Files representing the file names in the directory represented by this File that match a specific filter. If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.
Parameters:
  filter - the filter to match names to or null. an array of Files or null.
See Also:   File.list(FilenameFilter filter)
See Also:   File.getPath
See Also:   File.isDirectory
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)




listFiles
public File[] listFiles(FileFilter filter)(Code)
Answers an array of Files representing the file names in the directory represented by this File that match a specific filter. If this File is not a directory the result is null. If the filter is null then all filenames match.

The entries . and .. representing current directory and parent directory are not returned as part of the list.
Parameters:
  filter - the filter to match names to or null. an array of Files or null.
See Also:   File.getPath
See Also:   File.isDirectory
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)




listRoots
public static File[] listRoots()(Code)
Lists the filesystem roots. The Java platform may support zero or more filesystems, each with its own platform-dependent root. Further, the canonical pathname of any file on the system will always begin with one of the returned filesystem roots. the array of filesystem roots



mkdir
public boolean mkdir()(Code)
Creates the directory named by the trailing filename of this File. Not all directories required to create this File are created. true if the directory was created,false otherwise.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



mkdirs
public boolean mkdirs()(Code)
Create all the directories needed for this File. If the terminal directory already exists, answer false. If the directories were created successfully, answer true. true if the necessary directories were created,false otherwise.



properPath
byte[] properPath(boolean internal)(Code)
Answer a String representing the proper path for the receiver. If the receiver is absolute do not prepend the user.dir property, otherwise do.
Parameters:
  internal - is user.dir internal the proper path



renameTo
public boolean renameTo(java.io.File dest)(Code)
Renames this File to the name represented by the File dest. This works for both normal files and directories.
Parameters:
  dest - the File containing the new name. true if the File was renamed, falseotherwise.
See Also:   File.getPath
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



setLastModified
public boolean setLastModified(long time)(Code)
Sets the time this File was last modified.
Parameters:
  time - The time to set the file as last modified. the time this File was last modified.
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



setReadOnly
public boolean setReadOnly()(Code)
Marks this file or directory to be read-only as defined by the operating system. true if the operation was a success,false otherwise



toString
public String toString()(Code)
Answers a string containing a concise, human-readable description of the receiver. a printable representation for the receiver.



toURI
public URI toURI()(Code)
Answers a file URI for this File. The URI is System dependent and may not be transferable between different operating/file systems. a file URI for this File.



toURL
public URL toURL() throws java.net.MalformedURLException(Code)
Answers a file URL for this File. The URL is System dependent and may not be transferable between different operating/file systems. a file URL for this File.
throws:
  java.net.MalformedURLException - if the path cannot be transformed into an URL



Methods inherited from java.lang.Object
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object object)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final public Class<? extends Object> getClass()(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
final public void notify()(Code)(Java Doc)
final public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final public void wait(long millis, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait(long millis) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.