• Register
1 vote



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"));


12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

0 votes


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


13 9 6
94,240 points

Related questions

1 vote
1 answer 834 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 52 views
I am new to this. I was doing that but I got into some problems.
asked Nov 6, 2020 TeamScript 9.3k points
0 votes
1 answer 3 views
Problem: why the default implementation is useless (it’s hard to think of one which wouldn’t be, but yeah) __repr__ goal is to be unambiguous __str__ goal is to be readable Container’s __str__ uses contained objects’ __repr__
asked Jan 9 Mashhoodch 5.6k points
0 votes
1 answer 16 views
Problem Hey, what is the difference between null and null pointer. Answer me with the help of an example.
asked Dec 17, 2020 chris jordan 2.2k points
0 votes
1 answer 14 views
it will be of great help ,if you define what is __repr__ in python...
asked Nov 3, 2020 user1 160 points
0 votes
0 answers 30 views
I saw this code to find difference between diagonal sums of a square matrix. #!/bin/python3 import math import os import random import re import sys def diagonalDifference(arr): d1=0 d2=0 a=n-1 print(arr[1][1]) for i in range(0,n): d1+=arr[i][i] ... ['OUTPUT_PATH'], 'w') with fptr = sys.stdout, the output shows no difference. What then is the difference between functions of these two statements?
asked Oct 29, 2020 psandprop 2.4k points
0 votes
1 answer 46 views
Problem: Hello! My question is that what is endl and what is the difference between endl and \n in c++?
asked Oct 14, 2020 Code Learner 5.3k points
0 votes
2 answers 6 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, 2020 anonymous
0 votes
1 answer 12 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, 2020 SapperIt 1.2k points