2

This piece of scala code:

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

Throws:

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

While making the scala.io.Source.fromFile call. How is this possible and how can I fix it?

PS: This is in the context of a playframework app test.

1 Answer 1

2

Maybe because:

assert(file.isDirectory)

passes as well? You cannot really open a directory and read it, you can only open files. BTW on my machine the error is more descriptive:

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

Tested on:

$ java -version
java version "1.6.0_26"
$ scala -version
Scala code runner version 2.9.1.final
Sign up to request clarification or add additional context in comments.

3 Comments

Good point, but doing new File("./FileName.java") doesn't solve the issue either :(
@PabloFernandez: you're saying that file.exists is true but still you get FileNotFoundException? What about calling new FileInputStream(file)?
sorry I had another error on my app that was causing the issue. Your answer is correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.