Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin Paths.get给了我NoSuchFileException?_File_Kotlin_Path - Fatal编程技术网

Kotlin Paths.get给了我NoSuchFileException?

Kotlin Paths.get给了我NoSuchFileException?,file,kotlin,path,File,Kotlin,Path,问题: 我正在尝试将名为“test.txt”的文件从目录a移动到目录B val sourcePath = Paths.get("C:/Users/DGH/Pictures/TestImages/test.txt"); val targetPath = Paths.get("C:/Users/DGH/Pictures/TestOutputImages/test.txt"); Files.move(sourcePath, targetPath, StandardCopyOpt

问题:

我正在尝试将名为“test.txt”的文件从目录a移动到目录B

    val sourcePath = Paths.get("C:/Users/DGH/Pictures/TestImages/test.txt");
    val targetPath = Paths.get("C:/Users/DGH/Pictures/TestOutputImages/test.txt");
    Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
我完全确定文本文件存在于Pictures/TestImages/test.txt

即使我直接在文件资源管理器中复制粘贴路径,它也会打开文本文件

但是,如果我运行这段代码,它会在线程“main”java.nio.file.NoSuchFileException中给我一个异常:C:\Users\DGH\Pictures\TestImages\test.txt

我试过什么:

  • 让路径以斜线开始,因此
get(“/C:/Users/DGH/Pictures/TestImages/test.txt”)

  • 将斜杠替换为双反斜杠,以便
get(“C:\Users\DGH\Pictures\TestImages\test.txt”)


有人知道为什么这会给我一个NoSuchFileException,我能做些什么来修复它吗?

如果这是Windows,那么路径分隔符应该是“\”-但是请注意,这是一个特殊字符,所以要得到一个包含“\”的字符串,你需要在源代码中输入“\”。@gidds这不是真的。正斜杠很好,它们在内部转换为反斜杠。我在我的机器上运行了这段代码(使用不同的路径,但使用相同的正斜杠),它正在工作。zerk你确定这些文件不是符号链接吗?使用java.nio.file导入所有统计信息?