Q:

"URI is not hierarchical" when running JavaFX application on NetBeans

I am getting this "URI is not hierarchical" error when I run a JavaFX application. The exception is thrown in line 4 of the code below. Do you know how could I fix this?
001          { // HISTORY
002              try {
003                  URI uri = MainClass.class.getResource("history.txt").toURI();
004                  File f = new File(uri);
005                  String text = FileUtils.readFileToString(f);
006                  historyTextArea.setText(text);
007              } catch (URISyntaxException | IOException ex) {
008                  Constants.LOGGER.log(Level.SEVERE, ex.toString());
009              }
010          }

.
URI is not hierarchical
file:/C:/Users/Carlos/Desktop/projetos_java/CodePaster/dist/CodePaster.jar!/com/googlecode/codepaster/gui/about.fxml
  at java.io.File.<init>(File.java:392)
  at com.googlecode.codepaster.gui.AboutWindowController.initialize(AboutWindowController.java:142)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2152)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2694)
  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2683)
  at com.googlecode.codepaster.MainClass.start(MainClass.java:97)
  at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
  at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
  at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
  at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
  at java.lang.Thread.run(Thread.java:722)

A:

The problem is that you have a URI that refers to a resource inside a JAR file.  The File(URI) constructor cannot cope with a URI like that.  It only understands URIs for files.
What you need to do is something like this:
    String text;
    try (InputStream is = MainClass.class.getResourceAsStream("history.txt")) (
        text = IOUtils.toString(is);
    } catch (...

