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
1
vote
1 answer

How does the JAVA Scanner class work internally?

In JAVA when you import the Scanner class and create a Scanner object, how does the underlying logic work to capture the input and write it onto memory? I understand that the following statement Scanner sc = new Scanner (System.in) means you are…
mrarvind901
  • 11
  • 1
  • 2
1
vote
1 answer

Can't get Gradle to use System.in

This question explains how to use System.in when running a task to run a specific class in a project. But for me currently it's not working: although I have included the application plugin and the following lines in build.gradle: mainClassName =…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
1
vote
1 answer

java writing letters in console before user input

I am writing simple socket chat using console to output messages. The problem is that when one user types a message, and at the same time getting one, his input interrupted: I: writing my input here, but Other_user: hi! here is a message for you. I:…
Worm359
  • 87
  • 12
1
vote
0 answers

File I/O Redirect System.in fails while Normal file read with given path works properly

I am reading a PCAP file byte by byte in Java using IO-Redirection System.in. It does not reads the bytes in correct manner. I am using System.in.read(byte[], int off, int len); When I do the same thing with InputStream is = new…
Abhijit
  • 175
  • 5
  • 16
1
vote
2 answers

Java do-while loop skipping console input

class Noob1 { public static void main(String args[]) throws java.io.IOException{ char ch, answer; answer = 'g'; do { System.out.println("Guess from A-L:"); ch = (char) System.in.read(); …
naike
  • 11
  • 3
1
vote
1 answer

Can java system.in work together with input source code at same time without using thread

Saying my requirement is: Either user type something in console (from system.in) or socket receive something, proceed to next step. So I have a scanner Scanner sc = new Scanner(System.in); Have an Udp client. (a different input…
TTTTTAAOOOO
  • 43
  • 1
  • 6
1
vote
2 answers

Getting null value from bufferedreader

I am not able to understand why I am getting null from bufferedreader in following code (2nd line of output), while it worked fine at some places (1st line of output). I have used several system.out.println's just for debugging purpose. Although the…
Flying disk
  • 120
  • 7
1
vote
3 answers

Clear Scanner(in)

on my code, I've a long loop of sequential operation. I make a thread to stop this loop manually. Basically private static void sendAndCheck() throws InterruptedException { stop = false; StopChecker r = new StopChecker(); …
Lele
  • 703
  • 3
  • 15
  • 34
1
vote
0 answers

Java: How to use System.in Several times in one program?

On my previous question I've learned that I shouldn't close the System.in, and I also learned that using multiple Scanner together can cause problems. The problem is that I need some methods recursively to use the Scanner to scan some inputs from…
Harout Tatarian
  • 431
  • 4
  • 14
1
vote
2 answers

Why does System.in.read() wait till the user presses enter?

System.in.read() is used to read a single character. Then why does it allow the user to enter as many characters as he can until he presses enter? Why doesn't it stop as soon as he presses a key and returns the character? char ch =…
Uma Kanth
  • 5,659
  • 2
  • 20
  • 41
1
vote
1 answer

Common way to use System.in several times without closing

I have a console menu that has to read inputs a few times in different methods. I use a new BufferedReader(new InputStreamReader(System.in)) to do that. But if this reader is closed in a method it's not useable/openable again because of…
cmtjk
  • 359
  • 2
  • 12
1
vote
1 answer

"input line is too long" when entering string in Java console

When I input a string of 4500 characters followed by a newline feed in Java console, it displays input line is too long runtime error in the terminal. I have tried using both Scanner and BufferedReader, but no success.
user4392919
1
vote
2 answers

Java Scanner while loop

I'm trying to take in a string input which consists of multiple lines of numbers separated by ',' and ';' . Example: 1,2;3,4;5,6; 9,8;7,6; 0,1; ; Code: ArrayList alist = new ArrayList<>(); String delims = ";|\\,"; int i =…
fralewsmi
  • 92
  • 2
  • 12
1
vote
3 answers

After getting user input "Scanner name = new Scanner(System.in);" how to use is in a if statement?

So im learning java,bit by bit im getting a bit more knowledge, now im following tutroials and other webistes ect on learning but im stuck on one problem where i can't figure out what's the problem. import java.util.Scanner; class apples{ …
1
vote
1 answer

How come when i read an in from System.in I get a completely different value than I read in?

Here's the code: public static void main(String args[]) throws IOException { int i = System.in.read(); System.out.println(i); } When I input 13 for example it prints out 49..? why is that? And how do I fix that?
user3011240
  • 87
  • 2
  • 8