Issue
trying to register a new user and the login part is done only the registering im having issues. it says illegal escape character but run successfully
package register;
import java.io.File;
import java.io.IOException;
public class Register {
public static void main(String[] args)
{
try{
File newUser = new File ("C:\Users\Rohani\Desktop\Filehandling\newUser.txt"); //theres an error saying illegal escape char
if (newUser.createNewFile()){
System.out.println("User created: " + newUser.getName());
}else{
System.out.println("User already exist.");
}
} catch(IOException e ){
System.out.println("An error has occured.");
}
}
Solution
The \
char is used for escaping in Java Strings.
You can use \\
instead of \
or use /
.
Duplicate of:
Windows escape sequence issue with file path in java
Answered By - Francesc Montserrat