Java scala.io.Source找不到现有文件

Java scala.io.Source找不到现有文件,java,scala,io,playframework,filenotfoundexception,Java,Scala,Io,Playframework,Filenotfoundexception,这段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.

这段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应用程序测试的背景下进行的。

可能是因为:

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

很好,但是使用
新建文件(“./FileName.java”)
也不能解决问题:(@PabloFernandez:您的意思是
File.exists
是真的,但仍然会得到
FileNotFoundException
?调用
新建FileInputStream(File)怎么样
?很抱歉,我的应用程序中出现了另一个导致问题的错误。您的回答是正确的