File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What is illegal escape character in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is illegal escape character in java" Watch "What is illegal escape character in java" New topic

What is illegal escape character in java

sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear Sir,
While complile this code the error message display that "Illegal escape character".Please guide me to rectify this code.

The data.txt file contains:->Sumanta,Sagar,Harish

Thanks and Regards
Sumanta Panda
[ November 21, 2008: Message edited by: Martijn Verburg ]
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142

I think you should write

If you want to write a \ in a String literal you have to write \\, anyway Java compiler interprets it as an escape character. Since no such escape characters as \T or \d the java compiler reports an error.
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

Miklos is indeed correct, shifting to the beginners forum, more people will gain benefit from this if they search there.

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Another option is using forward slashes. File is smart enough to convert those to backslashes when accessing the actual file system.

How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Generally speaking, when the compiler gives you an error message, it tells you more than just "illegal escape character". It will show you the line and even the exact spot it thinks the error actually is:

It GREATLY helps people help you if you post the ENTIRE message. This lets a reader instantly focus in on where the problem is, rather than having to parse you entire java file and GUESS.

Just a little helpful tip for next time.
[ November 21, 2008: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
zameel amjed

Joined: Feb 16, 2011
Posts: 14

And check letter case at the readLine method it should be:

I agree. Here's the link:
subject: What is illegal escape character in java
It's not a secret anymore!