Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

when I try to create a new file using:

File file =new File("C:\Documents and Settings\username\My Documents\Eclipse Workspace\CH10_BasicIO\ch10\datafile1");

I get the following error:

- Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

Why isn't what I'm sending as an argument a valid pathname?

[404 byte] By [thousea] at [2007-11-27 10:31:23]
# 1

You need to escape the \ character in a string, and the escape character is the \, so to get a single \ you need to use \\ in your string.

macrules2a at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 2

> You need to escape the \ character in a string, and

> the escape character is the \, so to get a single \

> you need to use \\ in your string.

thanks.

thousea at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 3

you r welcome

but

GIVE macrules2 THE DUKES

persona non grata

pbulgarellia at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 4

Forward slash will also work, and won't look as icky

new File("C:/a/b/c");

jverda at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 5

> Forward slash will also work, and won't look as icky

> new File("C:/a/b/c");

Where did you pick up this icky you've been using recently?

georgemca at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 6

> > Forward slash will also work, and won't look as

> icky

> > new File("C:/a/b/c");

>

> Where did you pick up this icky you've been

> using recently?

This is much better.

Forward slash is a proper file path delimiter. Backslash is for escape sequences.

jverda at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 7

> > > Forward slash will also work, and won't look as

> > icky

> > > new File("C:/a/b/c");

> >

> > Where did you pick up this icky you've been

> > using recently?

>

> This is much better.

>

> Forward slash is a proper file path delimiter.

> Backslash is for escape sequences.

heh heh no I mean the word icky!

georgemca at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 8

> heh heh no I mean the word icky!

ROFL! Oohhhhh!

Um, I don't know. I've been using it for a long time. It just seems appropriate in some cases. I didn't even realize I'd used it there. Even re-reading (well, re-skimming) my post to see if that was what you were talking about. It's a bit of a fnord for me I guess.

jverda at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 9

File file = new File("C:\\Documents and Settings\\username\\My Documents\\Eclipse Workspace\\CH10_BasicIO\\ch10\\datafile1");

leonardoauera at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...
# 10

> File file = new File("C:\\Documents and

> Settings\\username\\My Documents\\Eclipse

> Workspace\\CH10_BasicIO\\ch10\\datafile1");

See jverd's response

georgemca at 2007-7-28 18:09:16 > top of Java-index,Java Essentials,New To Java...