Class FileObject
- All Implemented Interfaces:
Serializable
,org.openide.util.Lookup.Provider
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
Add new listener to this object.void
Adds a listener to thisFileObject
and all its children and children or its children.byte[]
asBytes()
Reads the full content of the file object and returns it as array of bytes.asLines()
Reads the full content of the file line by line with default system encoding.Reads the full content of the file line by line.asText()
Reads the full content of the file object and returns it as string.Reads the full content of the file object and returns it as string.boolean
canRead()
Tests if this file can be read.final boolean
Checks whether this file can be reverted to a pristine state.boolean
canWrite()
Tests if this file can be written to.copy
(FileObject target, String name, String ext) Copies this file.createAndOpen
(String name) Creates new file in this folder and immediately opens it for writing.createData
(String name) Create new data file in this folder with the specified name.abstract FileObject
createData
(String name, String ext) Create new data file in this folder with the specified name.abstract FileObject
createFolder
(String name) Create a new folder below this one with the specified name.final void
delete()
Delete this file.abstract void
Delete this file.boolean
Test whether there is a file with the same basename and only a changed extension in the same folder.protected void
Fire file attribute change event.protected void
Fire file change event.protected void
Fire data creation event.protected void
Fire file deletion event.protected void
Fire folder creation event.protected void
Fire file rename event.abstract Object
getAttribute
(String attrName) Get the file attribute with the specified name.abstract Enumeration
<String> Get all file attribute names for this file.Return a FileObject with path where all symbolic links are resolved.abstract FileObject[]
Get all children of this folder (files and subfolders).Enumeration
<? extends FileObject> getChildren
(boolean rec) Enumerate all children of this folder.Enumeration
<? extends FileObject> getData
(boolean rec) Enumerate all data files in this folder.abstract String
getExt()
Get the extension of this file or folder.getFileObject
(String relativePath) Retrieve file or folder relative to a current folder, with a given relative path.getFileObject
(String relativePath, boolean onlyExisting) Retrieve file or folder relative to a current folder, with a given relative path.abstract FileObject
getFileObject
(String name, String ext) Retrieve file or folder contained in this folder by name.abstract FileSystem
Get the filesystem containing this file.Enumeration
<? extends FileObject> getFolders
(boolean rec) Enumerate the subfolders of this folder.abstract InputStream
Get input stream.org.openide.util.Lookup
A lookup containing various logical views of the underlying represented file.Get the MIME type of this file.getMIMEType
(String... withinMIMETypes) Resolves MIME type from the list of acceptable ones.abstract String
getName()
Get the name without extension of this file or folder.Getter for name and extension of a file object.final OutputStream
Get output stream.abstract OutputStream
getOutputStream
(FileLock lock) Get output stream.getPackageName
(char separatorChar) Deprecated.Please use the ClassPath API instead.getPackageNameExt
(char separatorChar, char extSepChar) Deprecated.Please use the ClassPath API instead.abstract FileObject
Get parent folder.getPath()
Get the full resource path of this file object starting from the filesystem root.abstract long
getSize()
Get the size of the file.final URL
getURL()
Deprecated.UsetoURL()
instead.final boolean
Test whether this file has the specified extension.abstract boolean
isData()
Test whether this object is a data object.abstract boolean
isFolder()
Test whether this object is a folder.boolean
isLocked()
Test if file is lockedabstract boolean
Deprecated.Please use thecanWrite()
.abstract boolean
isRoot()
Test whether this object is the root folder.boolean
Check whether this FileObject is a symbolic link.abstract boolean
isValid()
Test whether the file is valid.boolean
Tests if file really exists or is missing.abstract Date
Get last modification time.abstract FileLock
lock()
Lock this file.move
(FileLock lock, FileObject target, String name, String ext) Moves this file.Read symbolic link.Read symbolic link path.void
refresh()
Should check for external modifications.void
refresh
(boolean expected) Should check for external modifications.abstract void
Remove listener from this object.void
Removes listener previously added byaddRecursiveListener(org.openide.filesystems.FileChangeListener)
abstract void
Renames this file (or folder).final void
revert()
Revert this file to a pristine state.abstract void
setAttribute
(String attrName, Object value) Set the file attribute with the specified name.abstract void
setImportant
(boolean b) Deprecated.No longer used.toString()
Gets a textual representation of thisFileObject
.final URI
toURI()
Gets a URI for this file.final URL
toURL()
Get URL that can be used to access this file.
-
Field Details
-
DEFAULT_LINE_SEPARATOR_ATTR
Name of default line separator attribute. File object can provide default line separator if it differs fromSystem.getProperty("line.separator")
. Callfo.getAttribute(DEFAULT_LINE_SEPARATOR_PROP)
returns string with default line separator. Default line separator will be used by the text editor if saving new content to an initially empty file. Any other code which creates file content programmatically must manually read this property if it cares.- Since:
- 7.56
- See Also:
-
DEFAULT_PATHNAME_SEPARATOR_ATTR
Name of default path name separator attribute. File object can provide default separator if it differs fromFile.separator
. Callfo.getAttribute(DEFAULT_PATHNAME_SEPARATOR_ATTR)
returns string with default separator.- Since:
- 9.6
- See Also:
-
-
Constructor Details
-
FileObject
public FileObject()
-
-
Method Details
-
getName
Get the name without extension of this file or folder. Period at first position is not considered as extension-separator For the root folder of a filesystem, this will be the empty string (the extension will also be the empty string, and the fully qualified name with any delimiters will also be the empty string).- Returns:
- name of the file or folder(in its enclosing folder)
-
getExt
Get the extension of this file or folder. Period at first position is not considered as extension-separator This is the string after the last dot of the full name, if any.- Returns:
- extension of the file or folder (if any) or empty string if there is none
-
rename
Renames this file (or folder). Both the new basename and new extension should be specified.Note that using this call, it is currently only possible to rename within a parent folder, and not to do moves across folders. Conversely, implementing filesystems need only implement "simple" renames. If you wish to move a file across folders, you should call
FileUtil.moveFile(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject, java.lang.String)
.- Parameters:
lock
- File must be locked before renaming.name
- new basename of fileext
- new extension of file (ignored for folders)- Throws:
IOException
-
copy
Copies this file. This allows the filesystem to perform any additional operation associated with the copy. But the default implementation is simple copy of the file and its attributes Since version 9.32, the file POSIX permissions are copied as well.- Parameters:
target
- target folder to move this file toname
- new basename of fileext
- new extension of file (ignored for folders)- Returns:
- the newly created file object representing the moved file
- Throws:
IOException
-
move
public FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException Moves this file. This allows the filesystem to perform any additional operation associated with the move. But the default implementation is encapsulated as copy and delete.- Parameters:
lock
- File must be locked before renaming.target
- target folder to move this file toname
- new basename of fileext
- new extension of file (ignored for folders)- Returns:
- the newly created file object representing the moved file
- Throws:
IOException
-
toString
Gets a textual representation of thisFileObject
. The precise format is not defined. In particular it is probably not a resource path. For that purpose usegetPath()
directly.Typically it is useful for debugging purposes. Example of correct usage:
FileObject fo = getSomeFileObject(); ErrorManager.getDefault().log("Got a change from " + fo);
-
getPath
Get the full resource path of this file object starting from the filesystem root. Folders are separated with forward slashes. File extensions, if present, are included. The root folder's path is the empty string. The path of a folder never ends with a slash.Subclasses are strongly encouraged to override this method.
Never use this to get a display name for the file! Use
FileUtil.getFileDisplayName(org.openide.filesystems.FileObject)
.Do not use this method to find a file path on disk! Use
FileUtil.toFile(org.openide.filesystems.FileObject)
.- Returns:
- the path, for example
path/from/root.ext
- Since:
- 3.7
- See Also:
-
getPackageNameExt
Deprecated.Please use the ClassPath API instead.Get fully-qualified filename. Does so by walking through all folders to the root of the filesystem. Separates files with providedseparatorChar
. The extension, if present, is separated from the basename withextSepChar
.Note:
fo.getPath()
will have the same effect as using this method with/
and.
(the standard path and extension delimiters).- Parameters:
separatorChar
- char to separate folders and filesextSepChar
- char to separate extension- Returns:
- the fully-qualified filename
-
getPackageName
Deprecated.Please use the ClassPath API instead.Get fully-qualified filename, but without extension. LikegetPackageNameExt(char, char)
but omits the extension.- Parameters:
separatorChar
- char to separate folders and files- Returns:
- the fully-qualified filename
-
getNameExt
Getter for name and extension of a file object. Dot is used as separator between name and ext.- Returns:
- string name of the file in the folder (with extension)
-
getFileSystem
Get the filesystem containing this file.Note that it may be possible for a stale file object to exist which refers to a now-defunct filesystem. If this is the case, this method will throw an exception.
- Returns:
- the filesystem
- Throws:
FileStateInvalidException
- if the reference to the file system has been lost (e.g., if the filesystem was deleted)
-
getParent
Get parent folder. The returned object will satisfyisFolder()
.- Returns:
- the parent folder or
null
if this objectisRoot()
.
-
isFolder
public abstract boolean isFolder()Test whether this object is a folder.- Returns:
- true if the file object is a folder (i.e., can have children)
-
lastModified
-
isRoot
public abstract boolean isRoot()Test whether this object is the root folder. The root should always be a folder.- Returns:
- true if the object is the root of a filesystem
-
isData
public abstract boolean isData()Test whether this object is a data object. This is exclusive withisFolder()
.- Returns:
- true if the file object represents data (i.e., can be read and written)
-
isValid
public abstract boolean isValid()Test whether the file is valid. The file can be invalid if it has been deserialized and the file no longer exists on disk; or if the file has been deleted.- Returns:
- true if the file object is valid
-
existsExt
Test whether there is a file with the same basename and only a changed extension in the same folder. The default implementation asks this file's parent usinggetFileObject(String name, String ext)
.- Parameters:
ext
- the alternate extension- Returns:
- true if there is such a file
-
delete
Delete this file. If the file is a folder and it is not empty then all of its contents are also recursively deleted.- Parameters:
lock
- the lock obtained by a call tolock()
- Throws:
IOException
- if the file could not be deleted
-
delete
Delete this file. If the file is a folder and it is not empty then all of its contents are also recursively deleted. FileObject is locked before delete and finally is this lock released.- Throws:
IOException
- if the file could not be deleted or FileAlreadyLockedException if the file is already lockedlock()
- Since:
- 1.15
-
getLookup
public org.openide.util.Lookup getLookup()A lookup containing various logical views of the underlying represented file. The lookup is supposed to containthis
FileObject
(however not necessarily only one, possibly more). The identity of the lookup should survivemove operation
- the resultingFileObject
after successful move will share the sameLookup
as the originalFileObject
. That is why one can putfileObject.getLookup()
intoIdentityHashMap
<Lookup,Anything>
and cacheAnything
regardless the actual location of (moved) file. Or one can obtain aLookup.Result
from theLookup
, keep its reference, attach a listener to it and be assured that it will fire events even if the file gets renamed.Inside of NetBeans Platform application the content of this lookup is usually identical to the one provided by the
DataObject.find(this).getLookup()
. This functionality is provided by theorg.netbeans.modules.settings
module.DataObject.move
operation preserves the object's identity, and to mimic the same behavior without reference to DataObject the behavior ofFileObject.getLookup()
has been modelled.- Specified by:
getLookup
in interfaceorg.openide.util.Lookup.Provider
- Returns:
- lookup providing logical interfaces additionally describing the content of the underlying file
- Since:
- 8.0
-
getAttribute
-
setAttribute
Set the file attribute with the specified name. The actual meaning of this method is implementation dependent. It is generally expected that the attribute will later be available fromgetAttribute(java.lang.String)
method.Many FileSystem implementations (since version 7.43) support special form of arguments for theirsetAttribute
method. One can use prefixmethodvalue:
ornewvalue:
to store references to Method or Class respectively. The meaning is then similar toXMLFileSystem
attributesmethodvalue
andnewvalue
.- Parameters:
attrName
- name of the attributevalue
- new value ornull
to clear the attribute. Must be serializable, although particular filesystems may or may not use serialization to store attribute values.- Throws:
IOException
- if the attribute cannot be set. If serialization is used to store it, this may in fact be a subclass such asNotSerializableException
.
-
getAttributes
Get all file attribute names for this file.- Returns:
- enumeration of keys (as strings)
-
hasExt
Test whether this file has the specified extension.- Parameters:
ext
- the extension the file should have- Returns:
- true if the text after the last period (
.
) is equal to the given extension
-
addFileChangeListener
Add new listener to this object.- Parameters:
fcl
- the listener
-
removeFileChangeListener
Remove listener from this object.- Parameters:
fcl
- the listener
-
addRecursiveListener
Adds a listener to thisFileObject
and all its children and children or its children. It is guaranteed that whenever a change is made via the FileSystem API itself under thisFileObject
that it is notified to thefcl
listener. Whether external changes (if they make sense) are detected and notified depends on actual implementation. As some implementations may need to perform non-trivial amount of work during initialization of listeners, this methods can take long time. Usage of this method may consume a lot of system resources and as such it shall be used with care. TraditionaladdFileChangeListener(org.openide.filesystems.FileChangeListener)
is definitely preferred variant.If you are running with the MasterFS module enabled, it guarantees that for files backed with real
File
, the system initializes itself to detect external changes on the whole subtree. This requires non-trivial amount of work and especially on slow disks (aka networks ones) may take a long time to add the listener and also refresh the system whenrefresh()
and especiallyFileUtil.refreshAll()
is requested.- Parameters:
fcl
- the listener to register- Since:
- 7.28
-
removeRecursiveListener
Removes listener previously added byaddRecursiveListener(org.openide.filesystems.FileChangeListener)
- Parameters:
fcl
- the listener to remove- Since:
- 7.28
-
fireFileDataCreatedEvent
Fire data creation event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
fireFileFolderCreatedEvent
Fire folder creation event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
fireFileChangedEvent
Fire file change event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
fireFileDeletedEvent
Fire file deletion event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
fireFileAttributeChangedEvent
protected void fireFileAttributeChangedEvent(Enumeration<FileChangeListener> en, FileAttributeEvent fe) Fire file attribute change event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
fireFileRenamedEvent
Fire file rename event.- Parameters:
en
- listeners that should receive the eventfe
- the event to fire in this object
-
getMIMEType
Get the MIME type of this file. The MIME type identifies the type of the file's contents and should be used in the same way as in the Java Activation Framework or in thejava.awt.datatransfer
package.The default implementation calls
FileUtil.getMIMEType(java.lang.String)
. (As a fallback return value,content/unknown
is used.)- Returns:
- the MIME type textual representation, e.g.
"text/plain"
; nevernull
-
getMIMEType
Resolves MIME type from the list of acceptable ones. By default callsFileUtil.getMIMEType(org.openide.filesystems.FileObject, java.lang.String[])
, but subclasses may override this method to be more effective.- Parameters:
withinMIMETypes
- A hint to the underlaying infrastructure to limit the search to given array of MIME types.- Returns:
- the MIME type for the FileObject, or
null
if the FileObject is unrecognized. It may returncontent/unknown
instead ofnull
. It is possible for the resulting MIME type to not be a member of givenwithinMIMETypes
list. - Since:
- 7.50
-
getSize
public abstract long getSize()Get the size of the file.- Returns:
- the size of the file in bytes or zero if the file does not contain data (does not exist or is a folder).
-
getInputStream
Get input stream.- Returns:
- an input stream to read the contents of this file
- Throws:
FileNotFoundException
- if the file does not exists, is a folder rather than a regular file or is invalid
-
asBytes
Reads the full content of the file object and returns it as array of bytes.- Returns:
- array of bytes
- Throws:
IOException
- in case the content cannot be fully read- Since:
- 7.21
-
asText
Reads the full content of the file object and returns it as string.- Parameters:
encoding
- the encoding to use- Returns:
- string representing the content of the file
- Throws:
IOException
- in case the content cannot be fully read- Since:
- 7.21
-
asText
Reads the full content of the file object and returns it as string. This is similar to callingasText(java.lang.String)
with default system encoding.- Returns:
- string representing the content of the file
- Throws:
IOException
- in case the content cannot be fully read- Since:
- 7.21
-
asLines
Reads the full content of the file line by line with default system encoding. Typical usage is infor
loops:for (String line : fo.asLines()) { // do something }
The list is optimized for iterating line by line, other operations, like accessing all the lines or counting the number of its lines may be suboptimal.
- Returns:
- list of strings representing the content of the file
- Throws:
IOException
- in case the content cannot be fully read- Since:
- 7.21
-
asLines
Reads the full content of the file line by line. Typical usage is infor
loops:for (String line : fo.asLines("UTF-8")) { // do something }
The list is optimized for iterating line by line, other operations, like accessing all the lines or counting the number of its lines may be suboptimal.
- Parameters:
encoding
- the encoding to use- Returns:
- list of strings representing the content of the file
- Throws:
IOException
- in case the content cannot be fully read- Since:
- 7.21
-
getOutputStream
Get output stream.- Parameters:
lock
- the lock that belongs to this file (obtained by a call tolock()
)- Returns:
- output stream to overwrite the contents of this file
- Throws:
IOException
- if an error occures (the file is invalid, etc.)
-
getOutputStream
Get output stream. This method does its best even when this file object is invalid - since version 9.23 it tries to recreate the parent hierarchy and really open the stream.- Returns:
- output stream to overwrite the contents of this file
- Throws:
IOException
- if an error occursFileAlreadyLockedException
- if the file is already locked- Since:
- 6.6
-
lock
Lock this file.- Returns:
- lock that can be used to perform various modifications on the file
- Throws:
FileAlreadyLockedException
- if the file is already lockedIOException
- (UserQuestionException) in case when the lock cannot be obtained now, but the underlaying implementation is able to do it after some complex/dangerous/long-lasting operation and request confirmation from the user
-
isLocked
public boolean isLocked()Test if file is locked- Returns:
- true if file is locked
- Since:
- 7.3
-
setImportant
Deprecated.No longer used. Instead useSharabilityQuery
.Indicate whether this file is important from a user perspective. This method allows a filesystem to distingush between important and unimportant files when this distinction is possible.For example: Java sources have important
.java
files and unimportant.class
files. If the filesystem provides an "archive" feature it should archive only.java
files.- Parameters:
b
- true if the file should be considered important
-
getChildren
Get all children of this folder (files and subfolders). If the file does not have children (does not exist or is not a folder) then an empty array should be returned. No particular order is assumed.- Returns:
- array of direct children
- See Also:
-
getChildren
Enumerate all children of this folder. If the children should be enumerated recursively, first all direct children are listed; then children of direct subfolders; and so on.- Parameters:
rec
- whether to enumerate recursively- Returns:
- enumeration of type
FileObject
-
getFolders
Enumerate the subfolders of this folder.- Parameters:
rec
- whether to recursively list subfolders- Returns:
- enumeration of type
FileObject
(satisfyingisFolder()
)
-
getData
Enumerate all data files in this folder.- Parameters:
rec
- whether to recursively search subfolders- Returns:
- enumeration of type
FileObject
(satisfyingisData()
)
-
getFileObject
Retrieve file or folder contained in this folder by name. Note that neither file nor folder is created on disk.- Parameters:
name
- basename of the file or folder (in this folder)ext
- extension of the file;null
or""
if the file should have no extension or if folder is requested- Returns:
- the object representing this file or
null
if the file or folder does not exist - Throws:
IllegalArgumentException
- ifthis
is not a folder
-
getFileObject
Retrieve file or folder relative to a current folder, with a given relative path. Note that neither file nor folder is created on disk. This method isn't final since revision 1.93. Since 7.45 common implementations of this method accept also ".." which is interpreted as a reference to parent.- Parameters:
relativePath
- is just basename of the file or (since 4.16) the relative path delimited by '/'- Returns:
- the object representing this file or
null
if the file or folder does not exist - Throws:
IllegalArgumentException
- ifthis
is not a folder
-
getFileObject
Retrieve file or folder relative to a current folder, with a given relative path. Note that neither file nor folder is created on disk. This method isn't final since revision 1.93. Since 7.45 common implementations of this method accept also ".." which is interpreted as a reference to parent.- Parameters:
relativePath
- is just basename of the file or (since 4.16) the relative path delimited by '/'onlyExisting
- iffalse
then a non-null
(butinvalid
file object is returned even if it doesn't exist- Returns:
- the object representing requested file or
null
(whenonlyExisting
is true) if the file or folder does not exist - Throws:
IllegalArgumentException
- ifthis
is not a folder- Since:
- 9.23
-
createFolder
Create a new folder below this one with the specified name. FiresFileChangeListener.fileFolderCreated(org.openide.filesystems.FileEvent)
.- Parameters:
name
- the name of folder to create. Periods in name are allowed (but no slashes).- Returns:
- the new folder
- Throws:
IOException
- if the folder cannot be created (e.g. already exists), or ifthis
is not a folder- See Also:
-
createData
Create new data file in this folder with the specified name. FiresFileChangeListener.fileDataCreated(org.openide.filesystems.FileEvent)
.- Parameters:
name
- the name of data object to create (can contain a period, but no slashes)ext
- the extension of the file (ornull
or""
)- Returns:
- the new data file object
- Throws:
IOException
- if the file cannot be created (e.g. already exists), or ifthis
is not a folder- See Also:
-
createData
Create new data file in this folder with the specified name. FiresFileChangeListener.fileDataCreated(org.openide.filesystems.FileEvent)
.- Parameters:
name
- the name of data object to create (can contain a period, but no slashes)- Returns:
- the new data file object
- Throws:
IOException
- if the file cannot be created (e.g. already exists), or ifthis
is not a folder- Since:
- 1.17
- See Also:
-
createAndOpen
Creates new file in this folder and immediately opens it for writing. This method prevents possible race condition which can happen when using thecreateData(java.lang.String)
method. Usingthat method
makes it possible for someone to read the content of the newly created file before its content is written. This method does its best to eliminate such race condition.This method usually delivers both,
data created
andchanged
events. Preferably it delivers them asynchronously. The assumption is that the file will be (at least partially) written before the listeners start to process the first event. The safety is additionally ensured by mutual exclusion between output and input streams for the same file (any call togetInputStream()
will be blocked for at least two seconds if there is existing open output stream). If you finish writing the content of your file in those two seconds, you can be sure, nobody will have read its content yet.- Parameters:
name
- name of file to create with its extension- Returns:
- output stream to use to write content of the file
- Throws:
IOException
- if the file cannot be created (e.g. already exists), or ifthis
is not a folder- Since:
- 7.41
-
isReadOnly
Deprecated.Please use thecanWrite()
.Test whether this file can be written to or not.The value returned from this method should indicate the capabilities of the file from the point of view of users of the FileObject's API, the actual state of the file on a disk does not matter if the implementation of the filesystem can change it when requested.
The result returned from this method should be tight together with the expected behaviour of
getOutputStream
. If it is likely that the method successfully returns a stream that can be written to, let theisReadOnly
returnfalse
.Also other fileobject methods like
delete
are suggested to be connected to result of this method. If not read only, then it can be deleted, etc.It is a good idea to call this method before attempting to perform any operation on the FileObject that might throw an IOException simply because it is read-only. If isReadOnly returns true, the operation may be skipped, or the user notified that it cannot be done. However it is often desirable for the user to be able to continue the operation in case the filesystem supports making a file writable. In this case calling code should:
- Call
lock()
and catch any exception thrown. - Then:
- If no exception is thrown, proceed with the operation.
- If a UserQuestionException is thrown,
call UserQuestionException#confirmed on it
(asynchronously - do not block any important threads). If
true
, proceed with the operation. Iffalse
, exit. If anIOException
is thrown, notify it and exit. - If another
IOException
is thrown, callisReadOnly()
. Iftrue
, ignore the exception (it is expected). Iffalse
, notify it.
- Returns:
true
if file is read-only
- Call
-
canWrite
public boolean canWrite()Tests if this file can be written to.The default implementation simply uses
java.io.File.canWrite
if there exists conversion tojava.io.File
(seeFileUtil.toFile(org.openide.filesystems.FileObject)
). If conversion is not possible, then deprecated methodisReadOnly()
is used.- Returns:
- true if this file can be written, false if not.
- Since:
- 3.31
-
canRead
public boolean canRead()Tests if this file can be read.The default implementation simply uses
java.io.File.canRead
if there exists conversion tojava.io.File
(seeFileUtil.toFile(org.openide.filesystems.FileObject)
). If conversion is not possible, thentrue
is returned.- Returns:
- true if this file can be read, false if not.
- Since:
- 3.31
-
canRevert
public final boolean canRevert()Checks whether this file can be reverted to a pristine state.- Returns:
- whether
revert()
might do something - Since:
- 7.55
-
revert
Revert this file to a pristine state. Generally only meaningful for files on the system filesystem (layers + user directory): if the file is defined in a layer but modified in the user directory, it is reset; if it is defined only in the user directory, it is deleted. IfcanRevert()
is false, does nothing. Note that while content can be reset, it may not be possible to reset attributes.Implementors: for historical reasons this method checks
getAttribute(java.lang.String)
for a special attribute namedremoveWritables
which must be of typeCallable<Void>
. If present, the file is considered modified.- Throws:
IOException
- Since:
- 7.55
-
refresh
public void refresh(boolean expected) Should check for external modifications. For folders it should reread the content of disk, for data file it should check for the last time the file has been modified.- Parameters:
expected
- should the file events be marked as expected change or not?- See Also:
-
refresh
public void refresh()Should check for external modifications. For folders it should reread the content of disk, for data file it should check for the last time the file has been modified.The file events are marked as unexpected.
-
getURL
Deprecated.UsetoURL()
instead.- Throws:
FileStateInvalidException
- never
-
toURL
Get URL that can be used to access this file. If the file object does not correspond to a disk file or JAR entry, the URL will only be usable within NetBeans as it uses a special protocol handler. Otherwise an attempt is made to produce an external URL.- Returns:
- URL of this file object
- Since:
- 7.57
- See Also:
-
toURI
-
isVirtual
public boolean isVirtual()Tests if file really exists or is missing. Some operation on it may be restricted.- Returns:
- true indicates that the file is missing.
- Since:
- 1.9
-
isSymbolicLink
Check whether this FileObject is a symbolic link. The default implementation returns false, but on filesystems that support symbolic links this method should be overriden.- Returns:
- True if this FileObject represents a symbolic link, false otherwise.
- Throws:
IOException
- If some I/O problem occurs.- Since:
- openide.filesystem/9.4
-
readSymbolicLink
Read symbolic link. If this FileObject represents a symbolic link, return a FileObject it refers to, or null if the referred file or directory does not exist. If this FileObject doesn't represent a symbolic link, the return value is undefined. The default implementation returns null, but on filesystems that support symbolic links this method should be overriden.- Returns:
- The referred FileObject, or null if it is not available.
- Throws:
IOException
- If some I/O problem occurs.- Since:
- openide.filesystem/9.4
-
readSymbolicLinkPath
Read symbolic link path. If this FileObject represents a symbolic link, return the path it refers to, which can be absolute or relative. If this FileObject doesn't represent a symbolic link, the return value is undefined. The default implementation returns this FileObject's path, but on filesystems that support symbolic links this method should be overriden.- Returns:
- The referred FileObject path.
- Throws:
IOException
- If some I/O problem occurs.- Since:
- openide.filesystem/9.4
-
getCanonicalFileObject
Return a FileObject with path where all symbolic links are resolved. The default implementation returns this object, but on filesystems that support symbolic links this method should be overriden.- Returns:
- The FileObject with path where all symlinks are resolved, or null if it doesn't exist.
- Throws:
IOException
- If some I/O problem occurs.- Since:
- openide.filesystem/9.4
-