【问题标题】:scala.io.Source not finding an existing filescala.io.Source 找不到现有文件
【发布时间】:2012-07-20 20:18:05
【问题描述】:

这段scala代码:

val file = new File(".")
assert(file.exists == true)
assert(file.getAbsolutePath.length > 0)
println(scala.io.Source.fromFile(file).getLines)

投掷:

FileNotFoundException: . (No such file or directory) (FileInputStream.java:120)

在拨打scala.io.Source.fromFile 时。这怎么可能,我该如何解决?

PS:这是在 playframework 应用测试的上下文中。

【问题讨论】:

    标签: java scala io playframework filenotfoundexception


    【解决方案1】:

    也许是因为:

    assert(file.isDirectory)
    

    也通过了?您不能真正打开目录并阅读它,您只能打开文件。顺便说一句,在我的机器上,错误更具描述性:

    java.io.FileNotFoundException: . (Is a directory)
    

    测试日期:

    $ java -version
    java version "1.6.0_26"
    $ scala -version
    Scala code runner version 2.9.1.final
    

    【讨论】:

    • 好点,但做new File("./FileName.java") 也不能解决问题:(
    • @PabloFernandez:你说file.exists 是真的,但你仍然得到FileNotFoundException?打电话给new FileInputStream(file)怎么样?
    • 抱歉,我的应用程序出现了另一个导致问题的错误。你的答案是正确的
    猜你喜欢
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多