> I am just intending to do some io with a file.
>
> so, you mean, in order to locate a file via a String,
> do something like:
>
> "C:\\xxx\\xxx\\xxx.doc"?
Not necessarily. For instance, if you're using the File class, then you can do "C:/x/y/z.doc"
and the slashes will be converted for you.
You do get that string, but the backslash can be used to create non-printable characters (among others) in string literals and thus needs to escape.
So the string literal "\\" will result in a string with 1 character length and that character beeing \. So even if it doesn't look like it you do indeed create a string that contains c:\xxx\ if your string literal looks like that: "c:\\xxx\\"
The text you had in your first reply (reply 2 of 6) will work in any situation that requires "\". "\" is an escape character that allows you to represent characters that would normally have other meanings as themselves. For example, how do you have a double quote in a literal string? Precede it with "\":String str = "Arm the \"laser beam\", please";
This would put the string Arm the "laser beam", please into str. Now, the escape can also escape itself. That's why you need two. The first \ is the escape character the second one is thus interpreted as a simple \ rather than an escape.
Does that clear things up?