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
2 answers

Declaring scanner to read system.in

Looking at Java tutorials, it seems you have to wrap up multiple layers of objects when declaring a scanner e.g. http://docs.oracle.com/javase/tutorial/essential/io/scanning.html s = new Scanner(new BufferedReader(new…
user3553107
  • 211
  • 1
  • 3
  • 6
1
vote
1 answer

How to close a scanner without closing the underlying System.in?

If I close one scanner object and make a new one and try to read some more input, I'm getting the NoSuchElementException exception. My code works fine but it gives me a warning if I don't close the scanner. However, if I close it to get rid of the…
Akshay Damle
  • 1,220
  • 3
  • 18
  • 31
1
vote
0 answers

How to send control chars using ExpectJ in interactive mode?

I've been using expectJ to automate some administrative tasks over ssh (jsch) for some time. It has been working well. Now I am facing an interface that accepts commands triggered by control characters. Such as CTRL+B for example. For…
Leo
  • 6,480
  • 4
  • 37
  • 52
1
vote
1 answer

Why cant my while-loop with system.in.read() get the last line in console?

Im stuck with a problem regarding System.in.read(). I want to print everything that is pasted into the console. My code looks like this: import java.io.IOException; public class printer { public static void main(String[ ] args) { int…
user3712130
  • 87
  • 1
  • 3
  • 8
1
vote
4 answers

reading char in loop

I want to read char variable a in a loop, and increment variable k by one in each step of loop. here is code in java: public class Hello { public static void main(String arg[]) throws IOException { int k, i; char a; k=0; for (i=0;…
Johny
  • 239
  • 2
  • 10
1
vote
1 answer

How to tell what type of input is being used in Java

I am writing a program in Java and I want it to accept two different methods of input. One would be piping a file into into the program like this: java program < inputFile.txt Another way I want the input is for the program to wait (in the middle of…
user2361174
  • 1,872
  • 4
  • 33
  • 51
1
vote
3 answers

"System.in.read()" in Java

I have a problem with this method: public void runTransaction(){ //Some calculations... wait(); //Other calculations... } private static void wait(){ try { System.out.println("Press to continue"); …
user3019653
  • 465
  • 1
  • 4
  • 7
1
vote
4 answers

Java 2 lines terminal input

For a school assignment I have to make a program that reads two numbers from the terminal and then processes those numbers. The program has to automatically process those two values once they have been entered. The code I have so far is down below,…
1
vote
1 answer

Why Java System.in.read() can call which is not a static method

In java, java.lang.System class, which has an in static variable. Declared as: public static final InputStream in Which means that in is an InputStream varibale. However I see some example, using System.in.read() to read input. How can it do…
loadload
  • 11
  • 2
1
vote
2 answers

java.util.Scanner strange behaviour when used with System.in

This simple piece of code: import java.util.Scanner; public class TestScanner { public static void main(String[] args){ Scanner sc1 = new Scanner(System.in); int number1 = sc1.nextInt(); sc1.close(); Scanner…
RGO
  • 4,586
  • 3
  • 26
  • 40
1
vote
4 answers

Java: Where is InputStream's read() method implemented when reading from System.in

Abstract class InputStream says that subclasses need to implement method read() which reads one byte and then turns it into an unsigned int. System.in is an InputStream and I can do: int i = System.in.read(); My question is.. where is this method…
fast-reflexes
  • 4,891
  • 4
  • 31
  • 44
0
votes
0 answers

Java: stop a Constructor when System.in reads in a specific String

I have some trouble with a Constructor in Java. The Problem is that I have to read-in some input from the Systme.in in the Constructor to initialize some final variable. Now i have to quit the Program when the input is "quit". For this, it's not…
Nexon
  • 3
  • 2
0
votes
0 answers

JShell: Scanner nextLine() NoSuchElementException when using /open

When using JShell's /open command to open a Java file and run code, user input does not work with Scanner. It will always throw a NoSuchElementException when it reaches the nextLine() method. Does anyone know why this is, and is there a…
0
votes
0 answers

Get JTextField input to System.in of different Java-program run by main program via console command?

I'm trying to code my own little Java IDE in Java. I'm pretty far for what I want, because I only want to be able to code simple command-line-programs in my IDE. My current problem has to do with user input. This is how I handle having an own…
0
votes
1 answer

Junit: how to stimulate the scanner.nextFloat() in testing?

I am writing Service for adding new Menu Items to Menu. Everything works fine with the tutorial which guided how to stimulate the System.in in Junit test. However, one parameter of Menu Items need to set to float value is Menu Item price. As a…