We help IT Professionals succeed at work.

# code file path in windows

on
i need to code the path to a file in windows.  How do i do that.
theFile = C:\new folder\new folder\new folder number two\xxx.txt.
When i compile it's seen as a illegal escape character.
Comment
Watch Question

## View Solution Only

Commented:
The backslash is an escape character. The direct way of fixing it would be to write:

theFile = "C:\\new folder\\new folder\\new folder number two\\xxx.txt";

A backslash escape followed by a backslash results in a backslash (as opposed to \n, for instance, which is a newline character).

For better platform independance you should use File.separator, so that it will insert backslash or forward slash depending on the system it is running on.

Commented:
actually you can just use "/" to separate it will work as the separator for all platforms i.e:
theFile = "C:/new folder/new folder/new folder number two/xxx.txt";

Commented:
Did you find this answer helpful? If so, then it is now time to grade the answer.

If not, perhaps a clarifying question would help.

Commented:
Sorry!!!.  Yeah.  First I forgot, then i was having trouble connecting.  Thanks.

Commented:
Sorry!!!.  Yeah.  First I forgot, then i was having trouble connecting.  Thanks.

Commented:
Sorry!!!.  Yeah.  First I forgot, then i was having trouble connecting.  Thanks.