Questions tagged [system.in]

Predefined stream object attached to the standard input in Java console applications.

It's a static variable in Java's System class. This tag is intended for questions about Java applications that read from the standard input.

191 questions
2
votes
1 answer

Scanner not working in ActionListener

I’m trying to simulate a console with a JTextArea by directing user input to System.in. The test string is successfully appended to the JTextArea, and the main method’s Scanner.nextLine() successfully waits for and prints user input. The same append…
2
votes
2 answers

Taking input from scanner and making a valid date

I know I can use the date formatter, but I'm trying to learn. I am trying to take a date from Scanner in the format of mm/dd/yyyy. I am having troubles when I take an input for the month. For example, if I want January I press 01 and monthInt…
Stepsie94
  • 29
  • 3
2
votes
3 answers

Java System.in hasNext method works only first time it is called

This problem has me stumped. I've written a method which is called from inside a loop. The first time it works perfectly, after that it just hangs. This is the method: public static String promptUser(){ String path = ""; Scanner reader = new…
clickcell
  • 439
  • 3
  • 6
  • 20
2
votes
1 answer

Java charset - How to get correct input from System.in?

my first post here. Well, i'm building a simple app for messaging through console(cmd and terminal), just for learning, but i'm got a problem while reader and writing the text with a charset. Here is my initial code for sending message, the…
ehbarbian
  • 73
  • 1
  • 6
2
votes
1 answer

Using CoderPad, why do I get a NoSuchElementException using a Scanner on System.in?

I am preparing for an interview I have in a few days. I was told that I should familiarize myself with CoderPad since that is the collaborator I will be interviewed with. However, I was in the middle of answering a question when I realized I could…
youngrrrr
  • 3,044
  • 3
  • 25
  • 42
2
votes
0 answers

Console default values when using Scanner(System.in)

I am trying to emulate this, $ are you sure (y,n)? y Where if the user hits enter, the default option would be read from nextLine() using the Scanner (default being the value already populated in the System.in which is in the above example the…
Faris
  • 875
  • 1
  • 9
  • 18
2
votes
1 answer

NumberFormatException when reading from System.in

I am getting these exception while running the code Exception in thread "main" java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) at java.lang.Integer.parseInt(Integer.java:615) at…
Akash Kumar
  • 165
  • 1
  • 12
2
votes
1 answer

Java Scanner - Read line breaks in to a string?

I have a scanner that takes user input until ctrl+d and then a while loop which adds each word to a string and then prints it, but i'd like to know how to also include the new line indicators like \n in the string wherever there is a new…
2
votes
0 answers

Reading large amounts of text from command line

I'm trying to get text entered by a user, but there seems to be a limit on the number of characters that a user can type in. I'm using BufferedReader to read from System.in and this is what I had for my code originally: BufferedReader r = new…
BrockLee
  • 931
  • 2
  • 9
  • 24
2
votes
1 answer

Who manages System.in/System.out opening/closing?

It is known fact that System.in and System.out is a InputStream and PrintStream respectively. Thus it is a java.io Streams. When we work with streams we should open and close its. Also we should to catch a lot of exceptions. When we work with…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
2
votes
3 answers

Issue with java Scanner not taking nextLine on new instance

package sandbox2; import java.util.Scanner; public class Sandbox2 { public static void main(String[] args) { for (int i = 0; i < 5; i++) { String s = askForProperty("Enter value for " + i + ": "); …
Drifter64
  • 1,103
  • 3
  • 11
  • 30
2
votes
1 answer

System.in input, java but with apache ant

I have added few system.in inputs (user inputs) in an interactive way. I have created executable jar and I am using apache ant to compile and run the program. When I execute it with java -jar jarfile.jar, the program interacts fine and take the user…
Natha Kamat
  • 71
  • 1
  • 5
  • 16
2
votes
2 answers

Setting System.in to read from JTextField

I'm looking for direction on how to replace System.in with an InputStream that reads directly from a JTextField. So far my approach has pretty much been trial and error. I currently have; JTextField input = new JTextField(); System.setIn(new…
Jivings
  • 22,834
  • 6
  • 60
  • 101
1
vote
1 answer

How to cancel out reading input from console?

So I'm trying to make a console app that imposes a time limit to user. User is expected to enter a certain number, but after a certain amount of milis (10 secs), it will break out of that input mode and tell user that time has expired and program…
garbagecollector
  • 3,731
  • 5
  • 32
  • 44
1
vote
1 answer

Is there a way to reopen an input stream with withReader? - Groovy

I know that the input stream is automatically closed at the end of this kind of block in Groovy: def exec = "" System.in.withReader { println "input: " exec = it.readLine() } but is there a way to reopen the stream if I want to do…
talnicolas
  • 13,885
  • 7
  • 36
  • 56
1 2
3
12 13