In Java, you can use the Console:
  System.console().readLine("")
with the caveat that System.console() [1] can return null if no terminal is 
attached to the process.

Otherwise you can use a Scanner:
  Scanner scanner = new Scanner(System.in);
  scanner.nextLine()

or a BufferedReader:
  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  reader.readLine()
or
  reader.lines() 
if you want a Stream of all lines.

cheers,
Rémi

[1] http://download.java.net/java/jdk9/docs/api/java/lang/System.html#console--

----- Mail original -----
> De: "Koray" <burakko...@gmail.com>
> À: "Jim Laskey (Oracle)" <james.las...@oracle.com>
> Cc: nashorn-dev@openjdk.java.net
> Envoyé: Samedi 25 Février 2017 18:41:51
> Objet: Re: Getting Input From User

> This is exactly what I'm looking for. Is it possible to do this from
> inside a Java application? I have tried readLine() and readFully()
> methods before, but I'm guessing they are meant for the commandline
> tool only.
> 
> Burak
> On 2/25/17, Jim Laskey (Oracle) <james.las...@oracle.com> wrote:
>>>> jjs -scripting
>> jjs> var name = readLine("Your name >> ");
>> Your name >> Jim
>> jjs> print(name)
>> Jim
>>
>> That sort of thing?
>>
>> — Jim
>>
>>
>>> On Feb 25, 2017, at 5:24 AM, Koray <burakko...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> I apologize if this is not the place to ask, but I couldn't get a
>>> satisfying answer from anywhere else so this is kind of my last
>>> resort.
>>>
>>> Is there any built-in function to get input from a user when using
>>> NashornScriptEngine? print() method allows us to utilize both the
>>> default OutputStreamWriter (System.out) and any writers that we set
>>> using ScriptContext, but how can I make use of the reader which is
>>> used by the engine?
>>>
>>> Thank you,
>>> Burak
>>
>>
> 
> 
> --
> saygılarımla
> Burak Koray Polat

Reply via email to