I have some problem with read file .txt in .jar exutable.
I know I need to use getResourceAsStream
method, but I cannot read it.
I have .jar
file and I have the file "Baza pytan.txt" in mainclass, so I make it like this:
InputStream ten=getClass().getResourceAsStream("Baza pytan.txt");
if(ten == null){
throw new FileNotFoundException();
}
Scanner in = new Scanner(ten,"UTF-8");
String linia;
String[] tokens;
Can anyone help me in this problem?
I use read file in GUI program. In other GUI project I made the same method to read file and it worked perfectly with ResourceAsStream
, but in this GUI I don't really know why not.
structure in Quiz.jar\Programik: