简体   繁体   English

Netbeans当前项目文件路径

[英]Netbeans Current Project File Path

In Netbeans what is the correct way to get the file path of the currently Opened Project. 在Netbeans中,获取当前已打开项目的文件路径的正确方法是什么。 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. 在我正在开发的模块中,我需要为FileChooser获取Project的路径,但是我尝试的大部分内容只返回了它正在执行的模块的路径。 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 尝试通过查找获取Project实例然后

        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(); 由于File位于Project的目录中,因此它的DataObject正在查找用于创建树结构的DataNode,我只是简单地使用:((DataNode)getParentNode()。getParentNode()。getParentNode()。getParentNode 。())getDataObject()getPrimaryFile();

I'm not particulary fond of this method but it seems to work fine for now. 我不是特别喜欢这种方法,但它现在似乎工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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