0

I am using net beans for developing my application in windows environment .. I have a xml file in XML folder (under web pages folder) . I am using the following code to read the xml file:

String path=new File("XML/TableNamesAndColumnNames.xml").getAbsolutePath();

but it is giving no file found .. because I am getting the path like -

"C:\Documents and Settings\rajesh\My Documents\NetBeansProjects\ReportOfReuls\XML\TableNamesAndColumnNames.xml"

but if I use reverse slash i.e:

"C:/Documents and Settings/rajesh/MyDocuments/NetBeansProjects/ReportOfReuls/web/XML/TableNamesAndColumnNames.xml" 

I am getting the file.. Is the problem of Net Beans or windows ..

please any one suggest how to resolve this problem

Thanks in Advance. Raj

2
  • What do you mean by "I am getting the path like"? Please show a short but complete program demonstrating the problem if you can - or at least be clearer about what you're doing. Commented Sep 9, 2011 at 6:01
  • That should be fine with backslashes if you're running on Windows... how exactly are you using that path afterwards? Really, showing the code would be very helpful. Commented Sep 9, 2011 at 6:07

3 Answers 3

5

Raj

both path are different

see

C:\Documents and Settings\rajesh\My Documents\NetBeansProjects\ReportOfReuls\XML\TableNamesAndColumnNames.xml

second one is having extra web folder.

C:/Documents and Settings/rajesh/My Documents/NetBeansProjects/ReportOfReuls/**web**/XML/TableNamesAndColumnNames.xml

and I will suggest if you are using java use

/ for path separator.

as it will work on all os in java.

Sign up to request clarification or add additional context in comments.

1 Comment

Well spotted - that's almost certainly the problem, although it's not at all clear how the two paths were obtained. Maybe it's a typo - that's the problem with not seeing the code :(
1

\ is used for escape characters like \r is an escape character for carriage return, \n is newline,.... You have to escape your slashes

use \\ in stead of \

not sure that is causes your problem here but might be

2 Comments

You only need to escape them within string literals - here, the strings are being printed out.
Agreed but original post was rather unclear so just mentioned it
0

Java has a fix for this built in. You should not be hard coding separators due to platform inconsistencies. PC's and Mac's paths are flipped and if you don't want the paths to break use File.separator instead.

ie:

String I = File.separator;

String filePath = "C:"+ I +"Documents and Settings"+ I +"rajesh"+ I +"My...";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.