Finally I work it out. I adopt Boris the Spider's answer, and it works well in IDE but break down in exported Jar. Then I change
final InputStream is = loader.getResourceAsStream("text");
to
final InputStream is = loader.getResourceAsStream("./text");
Then it works both in IDE and JAR.