简体   繁体   中英

Netbeans Current Project File Path

In Netbeans what is the correct way to get the file path of the currently Opened Project. In the module I am developing I need to acquire the path of the Project for a FileChooser however most of what I tried simply returned the path of the module it is executing from. Is their a way to get the path of the Project that the method is run from?

Try to get a Project instance via lookup and then

        private String getProjectDirectory(final Project project) {
            try {
                FileObject projectDirectory = project.getProjectDirectory();
                return FileUtil.toFile(projectDirectory).getAbsolutePath();
            } catch (Exception e) {
                //ignore the exception
                return null;
            }
        }

Right click on the project. Click properties. Sources tab. The "Project Folder" path is at the top.

Well I somewhat figured it out though I don't exactly like the fix. Since the File is in the directory of the Project its executing from and its DataObject is in the lookup of the DataNode used to create the tree structure I simply used : ((DataNode)getParentNode().getParentNode().getParentNode().getParentNode()).getDataObject().getPrimaryFile();

I'm not particulary fond of this method but it seems to work fine for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM