Use File.seperator in place of "".
File f = new File("C:"+File.seperator+"test");
File.seperator returns "" and it is not treated as an escape character.
If your file test.txt
is saved in folder D:/MyFloder/MyPrograms you can do something like this
File f = new File("D:"+File.seperator+"MyFloder"+File.seperator+"MyPrograms"+File.seperator+"test.txt");
EDIT
You don't need to worry about OS
For Unix : File.separator = /
For Windows : File.separator =
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…