【问题标题】:file handling in java error escape characterjava错误转义字符中的文件处理
【发布时间】:2020-04-24 13:56:58
【问题描述】:

尝试注册新用户并且登录部分仅在注册时遇到问题。它说非法转义字符但运行成功

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

【问题讨论】:

    标签: java netbeans


    【解决方案1】:

    \ 字符用于在 Java 字符串中转义。

    您可以使用\\ 代替\ 或使用/

    复制:

    Windows escape sequence issue with file path in java

    【讨论】:

      【解决方案2】:

      您需要转义路径中的反斜杠。而不是写\ 替换它们为\\

      【讨论】:

        猜你喜欢
        • 2017-08-06
        • 2016-10-07
        • 2017-01-10
        • 1970-01-01
        • 1970-01-01
        • 2018-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多