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.

177 questions
68
votes
11 answers

Eclipse reading stdin (System.in) from a file

Is it possible for Eclipse to read stdin from a file?
Kevin
39
votes
8 answers

Reading in from System.in - Java

I am not sure how you are supposed to read in from system input from a Java file. I want to be able to call java myProg < file Where file is what I want to be read in as a string and given to myProg in the main method. Any suggestions?
Alex
  • 4,609
  • 9
  • 43
  • 65
33
votes
2 answers

Setting The Environment for System.in

I'm designing a console application for a server running RedHat. The end users should be able to run this app with any terminal of their choosing. (For example; Gnome Terminal, Putty SSH/ Telnet, MS Telnet Client and others). In most terminal…
flakes
  • 12,841
  • 5
  • 28
  • 69
31
votes
1 answer

How to use java.util.Scanner to correctly read user input from System.in and act on it?

This is meant to be a canonical question/answer that can be used as a duplicate target. These requirements are based on the most common questions posted every day and may be added to as needed. They all require the same basic code structure…
user177800
13
votes
4 answers

Writing data to System.in

In our application, we expect user input within a Thread as follows : BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); I want to pass that part in my unit test so that I can resume the thread to execute the rest of the…
Mesut
  • 866
  • 1
  • 7
  • 17
12
votes
3 answers

Close Scanner without closing System.in

I'm trying to re-factor a large and frequently used part of my application into separate methods to make it easier to maintain. Some of these methods asks the user for input and does input validation, so I've used a Scanner and System.in But when I…
deepy
  • 399
  • 3
  • 20
6
votes
2 answers

Closing BufferedReader and System.in

Reader rdr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(rdr); String s; s = br.readLine(); br.close(); Scanner sc = new Scanner(System.in); s = sc.nextLine(); System.out.print(s); I've noticed that if I close the…
Bogdan Tomi
  • 128
  • 2
  • 11
6
votes
2 answers

confusion about the behavior of the read() method of System.in in Java

I know that the System.in of the System class is an instance of a concrete subclass of InputStream because the read() method of InputStream is abstract and System.in must override this method. According to the document about the read() method of…
Gödel
  • 392
  • 2
  • 17
6
votes
2 answers

Docker Java Application failing at obtaining input from console

I am trying to create a docker image for my java application. At startup this application needs to be given a password (currently via console). I tried several methods of obtaining input however they have all failed. Is this a limitation of docker…
mangusbrother
  • 3,432
  • 10
  • 44
  • 81
6
votes
3 answers

Java: use NIO with System.in

Is it possible to use NIO with System.in? I would like to somehow treat 'stdin' as a selectable channel. Has anyone found a way to do this?
Justin
  • 4,271
  • 4
  • 29
  • 52
5
votes
1 answer

How to mock System.in?

Could you explain me please how to mock System.in correctly? I have a simple test and I assign values to @Test public void testBarCorrect() { System.setIn(new ByteArrayInputStream("7\n2\n3".getBytes())); someService().consume(); } Under…
Pasha
  • 1,438
  • 1
  • 13
  • 33
5
votes
1 answer

An alternative to reading input from Java's System.in

I’m working on the UVa Online Judge problem set archive as a way to practice Java, and as a way to practice data structures and algorithms in general. They give an example input file to submit to the online judge to use as a starting point (it’s the…
dvanaria
  • 6,073
  • 21
  • 58
  • 77
5
votes
4 answers

What is the type of System.out in Java?

I am just a newbie in Java. I was wondering the way System.out.println() is used. Out is a static field inside System class. The type of out is PrintStream. But when I saw the constructor of PrintStream class, it takes a parameter of type…
abhithakur88
  • 397
  • 5
  • 16
4
votes
1 answer

Ant ignores input from stdin

I'm trying to get command line input into a running java program that I started with ant. However, nothing of what I type in the terminal is redirected to System.in of the java process. Is this normal? I'm using Windows 7 and Ant 1.8.2. The part of…
Hinton
  • 2,111
  • 2
  • 25
  • 30
4
votes
2 answers

Fail to read Japanese Characters via System.in

Code: Scanner sc = new Scanner(System.in); System.out.println("Enter Name : "); String name = sc.nextLine(); System.out.println(name); String encoding = "UTF-8"; System.out.println(new String(name.getBytes(encoding),…
1
2 3
11 12