How does one redirect input to a kotlin program? I...
# codeforces
g
How does one redirect input to a kotlin program? I want the equivalent of this, so that I can try out my code locally https://stackoverflow.com/a/54084856
e
It does not work work from dialog yet, see: https://youtrack.jetbrains.com/issue/KT-28854
What I do is I make move my solution into a separate
solve
function, make in extension on
BufferedReader
and then write in `main`:
Copy code
fun main() {
    File("....").bufferedReader().use { it.solve() }
}
Copy code
fun BufferedReader.solve() { 
    readLine() // now it reads from file!
}
g
makes sense thanks
This doesn’t work for me. The program is stuck on first invocation of readLine()
e
You have to call readLine from a function that is extension on BufferedReader.
g
Yeah was doing that, but still doesn’t work https://pastebin.com/fAghCPXX
e
You are calling readLine from readInts which is not extension on BufferedReader.
g
Hmm, still doesn’t work https://pastebin.com/SY6uR42S
e
Now you are calling
kotlin.io.readLine()
instead of calling
readLine()
on
BufferedReader
which you've added as your extension receiver.