简体   繁体   English

使用java.nio.file.Paths接口时缺少方案(IllegalArgumentException)

[英]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.

相关问题 如何在 nashorn javascript 中使用 Paths(java.nio.file.Paths) - How to use Paths(java.nio.file.Paths) in nashorn javascript Java.nio.file.Paths为当前目录提供了错误的路径? - Java.nio.file.Paths is giving incorrect path for current directory? java.nio.file.Paths - 如何在迭代时跳过无法访问的文件/文件夹 - java.nio.file.Paths - How to skip unaccessible file/folder while iterating Java6中java.nio.file.Paths的替代方法 - Alternative to java.nio.file.Paths in Java6 使用 java.nio.file.Paths & jsfml loadFromFile 时发生死锁 - Deadlock occurring when using java.nio.file.Paths & jsfml loadFromFile JMeter - 在类'java.nio.file.Paths'中找不到静态方法get(java.lang.String) - JMeter - Static method get( java.lang.String ) not found in class'java.nio.file.Paths' 复制文件时,JMeter Bean Shell采样器错误“在类'java.nio.file.Paths中找不到静态方法get(java.lang.String)” - JMeter Bean Shell Sampler error “…Static method get( java.lang.String ) not found in class'java.nio.file.Paths” when copying files 使用java.nio时抛出IllegalArgumentException - Thrown IllegalArgumentException when using java.nio 使用NIO写入文件时缺少新行 - new line is missing while writing file using NIO 无法解析以下内容:java / nio / file / Paths; - Failed resolution of: java/nio/file/Paths;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM