Java以“file:/”开头时无法识别文件

时间:2016-12-05 21:35:45

标签: java file url

Java表示文件在有效文件路径时不存在,但以file:/开头。我可以使用子字符串来摆脱这个,但我不想把URL搞砸到其他操作系统。有没有办法解决这个问题?规范化URL无济于事。

3 个答案:

答案 0 :(得分:3)

private static readonly DateTime minDB_smallDateTime = new DateTime(1900,1,1);

private static bool IsBasicallyNull(string input)
{
    if (String.IsNullOrWhiteSpace(input))
        return true;

    DateTime output;
    var isValidDateTime = DateTime.TryParse(input, out output);

    if (isValidDateTime && output <= minDB_smallDateTime)
       return true;

    .... rest of checking code....
}

答案 1 :(得分:3)

java.io.File(String)期待一个抽象路径名。那就是“C:/ somefile”或“/ home / auser / somefile”。

如果您希望它是“file://”,那么

java.io.File(URI)就是您想要的。您只需执行new File(new URI(filename));

即可

我建议阅读URI Documentation以了解抽象路径名和统一资源标识符之间的区别

答案 2 :(得分:0)

文件文件=新文件(新网址.toURI());