Bella
Bella

Reputation: 3

How to get a relative path from a given absolute path

How do I get out of the absolute path:

"C:/Users/test1234/workspace/Read/Test.txt"

the relative path? I thought the corresponding relative path looks like this:

".../Read/Test.txt"

but the file is not found, although the .txt file lies in the same directory as the java program. The file could be read with the absolute path, but I need the relative one. Any idea?

Upvotes: 0

Views: 124

Answers (1)

drsbee
drsbee

Reputation: 96

There is no such thing as the relative path from an absolute path. It all depends on your current location.

But in your case I think you should replace the three dots by two dots. So make it:

"../Read/Test.txt"

(At least if your current location is C:/Users/test1234/workspace/Whatever/)

Upvotes: 1

Related Questions