[英]Missing scheme (IllegalArgumentException) while using java.nio.file.Paths interface
this is a really simple java question. 这是一个非常简单的java问题。 I am using Java 8 with eclipse kepler on a linux system.
我在Linux系统上使用Java 8和eclipse kepler。 I've been trying to try out NIO.2.
我一直试图尝试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:///
): 您的uri声明缺少文件方案(
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.