• Register
1 vote
20 views

Problem:

Hello,

I was trying to compile my java code but it throws me an error below:

invalid escape sequence (valid ones are \b \t \n \f \r \ \' \\ )" It happened when I was trying to taking input by a Scanner class in my code.

I am really quite new in java. So. it goes beyond my understanding. Could anyone please help me out from here? I must appreciate your help.

Here is the code snippet:

InputReader job = new InputReader
               (new InputReader("\My Documents\job\jobfile.txt"));

Thanks.

12 7 7
15,250 points

1 Answer

0 votes

Solution:

Well, you need to know the difference between \ and \\ first. In java, | is called an escape character. You need to use the \\ in your file path instead of \

Here you go:

InputReader job = new InputReader
               (new InputReader("\\My Documents\\job\\jobfile.txt"));

Now, this program should work fine without the error you were getting earlier. If you want to know more about escape character, please check this link

Thanks.

13 9 6
94,240 points

Related questions

1 vote
1 answer 418 views
418 views
Problem: So, guys, I am learning to handle the java scanner class and taking input from the user. Let’s come to my point quickly. I was thinking to write a java program that asking the user for input until they give a valid response. I do have an idea ... condition So, this is my raw flow-chart to write the program. Please correct me if I am wrong anywhere. Any sample program is appreciated.
asked Mar 23 Gavin 15.3k points
0 votes
1 answer 9 views
9 views
Problem: Hello! My question is that what is endl and what is the difference between endl and \n in c++?
asked Oct 14 Sheeza 2.3k points
0 votes
2 answers 5 views
5 views
Problem: I am facing this error while practicing some c++ related input-output statements. I really don't know why I am facing this error as according to me this suppose to be the syntax of the header file.
asked Oct 12 anonymous
0 votes
1 answer 4 views
4 views
Problem: Hello everyone, I am new to the programming I just want to know why we use header files and we are using iostream header in every other code file.What it has to do with my code. Thanks
asked Oct 12 SapperIt 1.2k points