Just get the DataObject as a cookie and go from there:

 Node n = ...;
DataObject dob = (DataObject) n.getCookie(DataObject.class);
if (dob == null) {
    // not a file node
} else {
    // could also get all files in the data object, if desired:
    FileObject fo = dob.getPrimaryFile();
    // do something with fo

In the other direction you can use DataObject.find and then DataObject.getNodeDelegate to get a node representing a file object.

Source: NetBeans FAQ