I am trying to read a file into my Java program using java.util.Scanner and I get the above message when I enter the code below (I am new to java) - can anyone help? (I looked at a similar message someone got with their own code, but it was too complex for me to use in my example!). I have Windows 7.
BufferedReader job = new BufferedReader
(new FileReader("\My Documents\JOBS\newfile.txt"));
Placing a '\' (backslash) in front of the character in the regular expression generates an 'Invalid escape sequence' compilation error. This only occurs when the regular expression is used in the text of the script.
Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences.
You need to escape the "\" in the file path.
BufferedReader job = new BufferedReader
(new FileReader("\\My Documents\\JOBS\\newfile.txt"));
\
is an escape character, use \\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With