Missing scheme (IllegalArgumentException) while using java.nio.file.Paths interface

十年热恋 提交于 2019-12-12 08:47:16

问题


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


回答1:


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");


来源:https://stackoverflow.com/questions/25167149/missing-scheme-illegalargumentexception-while-using-java-nio-file-paths-interf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!