Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-在NB平台应用程序中从同一个包加载文件_Java_File_Netbeans_Netbeans Platform - Fatal编程技术网

Java-在NB平台应用程序中从同一个包加载文件

Java-在NB平台应用程序中从同一个包加载文件,java,file,netbeans,netbeans-platform,Java,File,Netbeans,Netbeans Platform,我有下面的代码 public void vbsCalled() { try { String file = "src\\com\\first\\hello\\hello.vbs"; Runtime.getRuntime().exec("wscript " + file + " "); } catch (IOException ex) { Logger.getLogger(RunVBS.clas

我有下面的代码

public void vbsCalled() {
        try {
            String file = "src\\com\\first\\hello\\hello.vbs";
            Runtime.getRuntime().exec("wscript " + file + " ");
        } catch (IOException ex) {
            Logger.getLogger(RunVBS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
我正在使用netbeansIDE

场景1:

  • 我创建了一个新的java项目(新项目->java->java应用程序)
  • 项目结构如下所示:

    --Java Application1
      -Source Packages
        -com.first.hello //Package
           -ClassWhichHaveVbsCalledMethod.java
           -hello.vbs
    
    有了这个,我可以从同一个包调用hello.vbs,并且没有错误

    场景2:

  • 我创建了一个netbeans平台应用程序(新项目->netbeans模块->netbeans平台应用程序)
  • 项目结构如下所示:

    --Java Application1
      -Source Packages
        -com.first.hello //Package
           -ClassWhichHaveVbsCalledMethod.java
           -hello.vbs
    

    RunVBS.java
    具有
    vbscaled()
    方法,并与场景1在同一个包中使用
    hello.vbs

    现在,它在中查找文件

    “C:\application1\src\com\first\hello\hello.vbs”

    并显示未发现此类文件错误

    如何像场景1一样在netbeans平台应用程序中加载文件

  • 在项目的根目录中创建一个名为release的文件夹
  • 将hello.vbs移动到发布/文件夹
  • 使用InstalledFileLocator类获取文件的运行时路径
  • 下面是VBScaled()方法的外观

    public void vbsCalled() {
        try {
            File file = InstalledFileLocator.getDefault().locate(
                          "hello.vbs", // filename relative to the release/ directory
                          "com.first.hello", // Your module's code name base __not package!__
                          false);
            Runtime.getRuntime().exec("wscript " + file.getAbsolutePath() + " ");
        } catch (IOException ex) {
            Logger.getLogger(RunVBS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    有关更多详细信息,请参阅