1

I have a JAR with a text file in it. I want to read it using a Scanner

String path = this.getClass().getClassLoader().getResource(str).getPath();
Scanner sc = new Scanner(new File(path+"MyFile.txt"));  

path contains the path to the JAR. "MyFile.txt" is the file I want to read using a scanner.

It's not working and I'm not quite sure why. When I print out path, the actual file path looks like this "file:/home...". I tried cutting off "file:" but that didn't seem to solve the issue.

What exactly am I doing wrong?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Kaotic
  • 11
  • 1

0 Answers0