Reputation: 20222
I have the following Scala code:
import java.io.{FileInputStream, PrintStream, FileOutputStream}
object bulbs {
def main(args: Array[String]): Unit = {
System.setIn(new FileInputStream("./bulbs.in"))
System.setOut(new PrintStream(new FileOutputStream("./bulbs.out")))
}
}
As you can see, this uses Java classes to redirect STDIN, STDOUT to bulbs.in
and bulbs.out
. These files are in the same folder, and the name is spelled correctly.
However, I still get:
Exception in thread "main" java.io.FileNotFoundException: ./bulbs.in (No such file or directory)
I have also tried using "bulbs.in"
rather than "./bulbs.in"
Why is this happening?
Upvotes: 0
Views: 53
Reputation: 424
You can use both:
"bulbs.in"
"./bulbs.in"
You can also view directory that is searched for file with property
System.getProperty("user.dir")
Upvotes: 1
Reputation: 533530
The file is not in the directory you are trying to read it from.
Note, it is usually better to do this redirection on the command line and leave it up to the caller.
Upvotes: 2