• Register
1 vote
37 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

Please log in or register to answer this question.

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 1.3K views
1.3K 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, 2020 Gavin 15.3k points
0 votes
1 answer 4 views
4 views
Problrm: Hello ... Can anyone tell me that why I got this error? for each function f(n) and time t in the following table
asked Mar 23 Ifra 24.4k points
0 votes
1 answer 4 views
4 views
Problem: what is an escape sequence in java?
asked Mar 22 Dan phillip 4.8k points
0 votes
1 answer 3 views
3 views
Problem: I need someone to understand this problem and find out the solution. what is the next two letters in the sequence: a - e - f - h - i - k - l - m - …
asked Apr 6 Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Problem: what is the difference between form feed, new line, and carriage return? What is the difference between \t and a space? They all look the same...What do \b, \f, \n, \r do? What are the differences?
asked 3 days ago ummesalma 25.2k points
0 votes
1 answer 37 views
37 views
Problem: As seen , the first print statement produced an output where the \t got resolved into a vertical tab and is omitted in the output. On the other hand, in the second print statement, the \j persists, as no legal resolution for that sequence exists.
asked Jan 22 Mashhoodch 13k points
1 vote
1 answer 5 views
5 views
Problem: I’m new in C programming. I doesn’t know how to use \b and \r in C? Plese help me to learn.
asked Mar 6 Shovo210 13.8k points
0 votes
1 answer 2 views
2 views
Problem: Can two or more operators such as \n and \t be combined in a single line of program code?
asked 4 days ago nabin 3.2k points
0 votes
1 answer 4 views
4 views
Problem: How I can fix this: write a program that asks the user to type 10 integers of an array
asked Mar 19 Wafa Abu Yousef 6.1k points