This discussion is archived
1 Reply Latest reply: Nov 8, 2012 5:09 PM by jschellSomeoneStoleMyAlias RSS

Relative Path...?

973340 Newbie
Currently Being Moderated
Hello,

I have two .txt files I would like to add to a jar file for my program to read from. I'm not sure how the program is to read from the file if given the name of the file only. I can't give it the direct path to the files because when the jar file moves, they cannot be read. How would I be able to give the path to the files and have the jar read them where ever the jar is?

Thank You,
Pengu
  • 1. Re: Relative Path...?
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Presumably you ONLY want to read from them, never write, then the files are treated as a 'resource".

    Googling with the following seem to provide solutions to that.

    java io jar resource

    If you want to write to those files then you MUST extract them from the jar and put them into the file system. And of course once you put them into the file system, you will explicitly know where they are.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points