Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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 要在WebView中加载的文件路径有问题_Java_File_Javafx - Fatal编程技术网

Java 要在WebView中加载的文件路径有问题

Java 要在WebView中加载的文件路径有问题,java,file,javafx,Java,File,Javafx,我试图通过以下代码使用java将html文件加载到窗口中: public void showManual (ActionEvent event) { File myFile = new File("prueba/index.html"); Stage stage = new Stage(); stage.setTitle("Manual de ayuda"); stage.setWidth(500); stage.setHeight(600);

我试图通过以下代码使用java将html文件加载到窗口中:

    public void showManual (ActionEvent event) {

    File myFile = new File("prueba/index.html");
    Stage stage = new Stage();
    stage.setTitle("Manual de ayuda");
    stage.setWidth(500);
    stage.setHeight(600);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);
    webEngine.load(myFile.toURI().toString());

    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();

}

我使用的操作系统是Windows,myFile.toURI()返回给我的是这个文件:/E:/data/project/test/index.html,显然它不是有效的路径。有人能告诉我怎么办吗

您是否尝试过
myFile.toURI().toul().toString()
?HTML文件是外部文件还是嵌入式资源?如果我已经尝试过,但文件不在项目文件夹中,我正在使用windows和一个文件uri,在协议之后和驱动器号之前,这些空间对我来说从未出现过。但是这条路正确吗?通常您会对资源使用
Class.getResource()
,但是如果您指定了正确的路径,那么使用文件也应该可以。
myFile.exists()
返回什么?