Everywhere you can find lectures on how to import a class. How to import a file?
My example:

public class JavaApplication36 extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { System.out.println("Все хорошо"); Parent pane = FXMLLoader.load(getClass().getResource("fxml/scene1.fxml")); Scene scene = new Scene(pane, 700, 500); primaryStage.setScene(scene); primaryStage.setTitle("Адресная книга"); primaryStage.show(); } } 

enter image description here

If I start writing import , it simply underlines

    1 answer 1

    As far as I understand, you want to download the scene1.fxml file for further use.

    In Java, this is done using the getResource() or getResourceAsStream() methods, with the second there are fewer problems when running outside the development environment.

    In your case, you just need to specify the full batch path to your file:

     public class JavaApplication36 extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { System.out.println("Все хорошо"); Parent pane = FXMLLoader.load(JavaApplication36.class.getResource("Пакеты исходных кодов/fxml/scene1.fxml")); ^ использовать кириллицу в названиях нехорошо Scene scene = new Scene(pane, 700, 500); primaryStage.setScene(scene); primaryStage.setTitle("Адресная книга"); primaryStage.show(); } } 

    This code has not been verified, but I am almost sure that it will work.

    PS the import code word is used only for access with classes, interfaces, and enums (enum), but nothing else.

    • one
      thank you) another solution was: (../fxml/scene1.fxml) - michael_best
    • @michael_best Please, I also thought so, but this method can cause incomprehensible problems when running a compiled file ... or it may not cause it, as lucky (I still do not fully understand these diabolical methods :)) - 0x666c
    • one
      @Jiftoo Well, in one case the path will be built from the root of the project, in the other from JavaApplication36.class. - Maxim
    • @Maxim You are right, but this method is not suitable if the file you are looking for is higher than one package up. - 0x666c
    • one
      @Maxim An interesting solution - 0x666c