giving file path in unix and windows

hi,

i'm having problem with reading file from both windows and unix as now i give

if (os == win)

file="mydir\\mydir1\\myfile"

else

file="mydir/mydir1/myfile"

wherei get mydir* from environment.

and then open that file.

but i feel the above is clumsy and is more like C #ifdef

Can you please help me out on this.

Thanks & Regards

Rajkumar

[424 byte] By [rajkumar_sundaram] at [2007-9-26 18:29:41]
# 1
Two possibilities:String filename = "mydir" + File.separatorChar + "mydir1" + File.separatorChar + "myfile";File mydir = new File("mydir");File mydir1 = new File(mydir, "mydir1");File myfile = new File(mydir1, "myfile");
KJKrum at 2007-7-3 2:47:15 > top of Java-index,Archived Forums,Java Programming...
# 2

hi,

use the System property "file.separator" to figure out the seperator.

for eg

java.util.Properties prop = System.getProperties();

String separator = prop.getProperty("file.separator");

System.out.println("separator :" + separator);

hope that helpz

cheerz

ynkrish

ynkrish at 2007-7-3 2:47:15 > top of Java-index,Archived Forums,Java Programming...