Java NIO文件路径问题 [英] Java NIO file path issue

查看:1216
本文介绍了Java NIO文件路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码获取路径

I used the following code to get the path

Path errorFilePath = FileSystems.getDefault().getPath(errorFile);

当我尝试使用File NIO移动文件时,我收到以下错误:

When I try to move a file using the File NIO, I get the error below:

java.nio.file.InvalidPathException: Illegal char <:> at index 2: \C:\Sample\sample.txt

我也尝试过使用< a href =http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html#encode%28java.lang.String,java.lang.String%29 =noreferrer > URL.encode(errorFile) 会导致同样的错误。

I also tried using URL.encode(errorFile) which results in the same error.

推荐答案

路径 \ C:\ Sample\sample.txt 必须没有前导 \ 。它应该只是 C:\ Sample\sample.txt

The path \C:\Sample\sample.txt must not have a leading \. It should be just C:\Sample\sample.txt

这篇关于Java NIO文件路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆