Getting canonical path for file spec relative to another

I have a text file containing refererences to other files relative to itself.Is the only way to get the canonical path of these referenced files by temporarily setting the working directory to that of the original file, or is there an easier and better way?Thanks.
[285 byte] By [JeffG1a] at [2007-11-27 3:04:32]
# 1

Assuming you have File object representing the original text file and a file name relative to itself (assuming relative to the directory the original text file is in), you can get a canonical filename like this:File textFile = new File("C:\\Documents and Settings\\JeffG1\\My Documents\\references.txt");

File directory = textFile.getParentFile();

String relativeFileName = getRelativeFileName(); // get it somehow

File fileForFileName = new File(directory, relativeFileName);

System.out.println(fileForFileName.getCanonicalPath());

Note that this code does NOT check for the existence of the file.

Herko_ter_Horsta at 2007-7-12 3:49:08 > top of Java-index,Java Essentials,New To Java...
# 2
Many thanks! There are so many different constructors and methods available that it's not too easy to find just the one you want when you're new to a language.
JeffG1a at 2007-7-12 3:49:08 > top of Java-index,Java Essentials,New To Java...