使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException) [英] Missing scheme (IllegalArgumentException) while using java.nio.file.Paths interface
本文介绍了使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package lucasTest;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file。*;
public class Lucas {
public static void main(String [] args)throws URISyntaxException {
URI u = new URI(./ Lucas.java);
路径p = Paths.get(u);
}
}
我收到以下错误:
线程main中的异常java.lang.IllegalArgumentException:缺少方案
在java.nio.file.Paths.get(Paths。 java:134)
at lucasTest.Lucas.main(Lucas.java:10)
请帮助!
谢谢,
Lucas
解决方案
您的uri声明缺少文件方案( file:///
):
u = new URI(file:///./Lucas.java);
路径p = Paths.get(u);
应该工作。作为替代,您可以尝试
路径p2 = Paths.get(。,Lucas.java);
this is a really simple java question. I am using Java 8 with eclipse kepler on a linux system. I've been trying to try out NIO.2. My code is:
package lucasTest;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
public class Lucas {
public static void main(String[] args) throws URISyntaxException{
URI u = new URI("./Lucas.java");
Path p = Paths.get(u);
}
}
I get the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Missing scheme
at java.nio.file.Paths.get(Paths.java:134)
at lucasTest.Lucas.main(Lucas.java:10)
Please help!
Thanks, Lucas
解决方案
Your uri declaration is missing the scheme for files (file:///
):
u = new URI("file:///./Lucas.java");
Path p = Paths.get(u);
should work. As an alternative you can try
Path p2 = Paths.get(".", "Lucas.java");
这篇关于使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文