This Question is Answered

1 "correct" answer available (4 pts)
4 Replies Last post: Sep 21, 2012 5:19 PM by Renzo Leiner  
Renzo Leiner Newbie 7 posts since
Sep 21, 2012
Currently Being Moderated

Sep 21, 2012 2:46 PM

Input

Silly question: how can i read from standard input (not arguments line)?

Thx, regards.

Andrey Breslav Apprentice 566 posts since
Jun 11, 2007
Currently Being Moderated
Sep 21, 2012 4:49 PM in response to: Renzo Leiner
Re: Input
Nikolay Krasko Newbie 23 posts since
Jun 7, 2010
Currently Being Moderated
Sep 21, 2012 5:01 PM in response to: Renzo Leiner
Re: Input

Kotlin standard library contans println and readLine functions which could help in solving you task gracefully:

 

fun main(args: Array<String>) {
    println("Line: ${readLine()}") // Read line and print it back to console
}

 

In fact under the hood those functions are simple wrappers for java.io, and as kotlin is compatible with Java you can also choose to implement same program like this:

 

import java.io.InputStreamReader
import java.io.BufferedReader
 
fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    System.`out`.println("Line: ${reader.readLine()!!}")
}

More Like This

  • Retrieving data ...