Difference between revisions of "Get an absolute file path from a relative file path"

From CodeCodex

(Added common lisp implementation)
Line 1: Line 1:
 
==Implementations==
 
==Implementations==
 +
===Common Lisp===
 +
<pre>
 +
> (directory "filename.txt")
 +
 +
(#P"/home/Username/filename.txt")
 +
</pre>
 +
 
===Java===
 
===Java===
 
<pre>
 
<pre>

Revision as of 07:35, 16 December 2006

Implementations

Common Lisp

> (directory "filename.txt")

(#P"/home/Username/filename.txt")

Java

    File file = new File("filename.txt");
    file = file.getAbsoluteFile();  // c:\temp\filename.txt
    
    file = new File("dir"+File.separatorChar+"filename.txt");
    file = file.getAbsoluteFile();  // c:\temp\dir\filename.txt
    
    file = new File(".."+File.separatorChar+"filename.txt");
    file = file.getAbsoluteFile();  // c:\temp\..\filename.txt
    
    // Note that filename.txt does not need to exist