-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqFilesFromNodes
In general, it shall be enough to request a FileObject via Lookup:
Node n = ...;
FileObject fo = n.getLookup().lookup(FileObject.class);
if (fo != null) {
File f = FileUtil.toFile (fo);
if (f != null) { //if it is null, it is a virtual file -
//its filesystem does not represent disk-based storage
//do something
}
}
If this does not work for some (strange) reason. You may fallback to old good way and get the DataObject
the node represents, and drill down to a file from there
Node n = ...;
DataObject dob = n.getLookup().lookup(DataObject.class);
if (dob == null) {
// definitely not a file node
} else {
// could also get all files in the data object, if desired:
FileObject fo = dob.getPrimaryFile();
// and if you really need java.io.File
File f = FileUtil.toFile (fo);
if (f != null) { //if it is null, it is a virtual file -
//its filesystem does not represent disk-based storage
//do something
}
}
In the other direction you can use DataObject.find
and then DataObject.getNodeDelegate
to get a node representing a file object.
Also see DevFaqFileVsFileObject if you need java.io.File
for some reason.
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqFilesFromNodes , that was last modified by NetBeans user Jtulach on 2010-07-24T18:53:56Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.