使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException) [英] Missing scheme (IllegalArgumentException) while using java.nio.file.Paths interface

查看:1437
本文介绍了使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的java问题。我在linux系统上使用Java 8与eclipse开普勒。我一直试图尝试NIO.2。我的代码是:

  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屋!

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