p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

beginning_java thread: Relative paths

Message #1 by "Tolga K ÖZDEMİR" <ozdemit@y...> on Sat, 20 Apr 2002 21:03:30
Hi everbody,
I am currently reading chapter 8, Are there any ones who can explain me 
what a relative path is and how can I define a path for files to use them 
on different platforms?

Please explain in details and give me examples 

Thx for everything....   

Message #2 by "Ivor Horton" <ivor.horton@b...> on Mon, 22 Apr 2002 11:49:14 +0100
A pathname can have two parts - an optional prefix followed by a series of
names separated by a separator character. An absolute path is one that
includes the prefix. A relative path is a path that does not. Under Windows
the prefix is a string that defines the drive letter such as C:\\".

Defining paths in a platform independent way can be quite tricky because of
the different conventions for specifying paths on different systems. Systems
differ in the name and path separator characters they use - Windows uses a
backslash as a name separator whereas Unix uses a forward slash for
instance, and the way a prefix is defined also varies. The File class
defines static field that define the default spearator characters on the
current system. You can get information about the current environment by
calling the static getProperty() method in the System class. The argument to
the method is a String object specifying the name of the system property you
want. For instance "user.home" identifies the property that contains the
user home directory so to define a File object encapsulating a path to a
file in this directory in a system independent way you could write:

File aFile = new File(System.getProperty("user.home") + File.separator +


  Return to Index