public interface FileObject
File abstraction for tools. In this context, file means an abstraction of regular files and other sources of data. For example, a file object can be used to represent regular files, memory cache, or data in databases.
All methods in this interface might throw a SecurityException if a security exception occurs.
Unless explicitly allowed, all methods in this interface might throw a NullPointerException if given a null
argument.
URI toUri()
Returns a URI identifying this file object.
String getName()
Gets a user-friendly name for this file object. The exact value returned is not specified but implementations should take care to preserve names as given by the user. For example, if the user writes the filename "BobsApp\Test.java"
on the command line, this method should return "BobsApp\Test.java"
whereas the toUri method might return file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
.
InputStream openInputStream() throws IOException
Gets an InputStream for this file object.
IllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support byte accessIOException
- if an I/O error occurredOutputStream openOutputStream() throws IOException
Gets an OutputStream for this file object.
IllegalStateException
- if this file object was opened for reading and does not support writingUnsupportedOperationException
- if this kind of file object does not support byte accessIOException
- if an I/O error occurredReader openReader(boolean ignoreEncodingErrors) throws IOException
Gets a reader for this object. The returned reader will replace bytes that cannot be decoded with the default translation character. In addition, the reader may report a diagnostic unless ignoreEncodingErrors
is true.
ignoreEncodingErrors
- ignore encoding errors if trueIllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurredCharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException
Gets the character content of this file object, if available. Any byte that cannot be decoded will be replaced by the default translation character. In addition, a diagnostic may be reported unless ignoreEncodingErrors
is true.
ignoreEncodingErrors
- ignore encoding errors if truenull
otherwiseIllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurredWriter openWriter() throws IOException
Gets a Writer for this file object.
IllegalStateException
- if this file object was opened for reading and does not support writingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurredlong getLastModified()
Gets the time this file object was last modified. The time is measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
boolean delete()
Deletes this file object. In case of errors, returns false.
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.