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

How can I redirect System.in to JavaFX TextField?

I am working on new project. I am trying to send commands to external computer (Linux) through ethernet from Java. I am using Jsch to create shell connection. I set shell input and output to System.out and System.in.…
Zuzana
  • 67
  • 3
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),…
4
votes
0 answers

System out, in and err streams declared null

I looked at java.lang.System source code and found the following lines: public final static InputStream in = null; public final static PrintStream out = null; public final static PrintStream err = null; I know that a final reference can't be…
Brrch
  • 331
  • 1
  • 4
3
votes
1 answer

How can I fix an "IOException: Stream closed" exception using System.in?

I'm writing a simple program that reads and processes file content using a BufferedReader. BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Enter the file name to read"); String fileName =…
nikhil
  • 8,925
  • 21
  • 62
  • 102
3
votes
1 answer

Cygwin encoding difficulties

Not sure whether this is a programming problem. I began to suspect so... but then I ran the Java program (executable jar) in question in a Windows console instead of a Cygwin one... and it ran fine: output accents fine, accented input accepted fine.…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
3
votes
1 answer

Resetting FileInputStream in Java so I can run multiple instances of another program in a test program

My problem is that I was assigned to modify and improve upon a program that does LZW compression. My program, as far as I know, runs fine, but relies on System.in and System.out redirection for the input file and output file. For my test program, I…
3
votes
3 answers

Why won't Java print last word here?

Why does this print the entire string "1fish2fish"... import java.util.Scanner; class Main { public static void main(String[] args) { String input = "1,fish,2,fish"; Scanner sc = new Scanner(input); sc.useDelimiter(","); …
Travis Smith
  • 622
  • 5
  • 22
2
votes
1 answer

How to clear/reset/open an input stream so it can be used in 2 different methods in Java?

Here's the code: package testpack; import java.io.*; public class InputStreamReadDemo { private void readByte() throws IOException { System.out.print("Enter the byte of data that you want to be read: "); …
Petrus K.
  • 840
  • 7
  • 27
  • 56
2
votes
1 answer

Java incorrectly reading accented characters from System.in

If you are facing the same problem, and your character set is covered by the ANSI test encoding (codepage 1252 or "ISO 8859-1"), you could use that encoding instead to temporarily circumvent the problem with UTF-8, however UTF-8 is the modern…
ShadeOfLight
  • 87
  • 11
2
votes
2 answers

BufferedReader stuck at last input line without ending the program

I'm using BufferedReader to read data from System.in (a text file redirected context: < file.txt) then write it to the console. The problem is my program shows all lines except the last one and still works without doing any thing. If I manually end…
2
votes
0 answers

Java Simulate Scanner input on console failing with multiple inputs

I am trying to simulate multiple inputs in Java console with the help of Scanner. I need them for Unit testing but its failing only first few values are correctly taken but rest of them are ignored. Please have a look at the following code String…
PHP Avenger
  • 1,744
  • 6
  • 37
  • 66
2
votes
1 answer

How can I make multiple text based java menus work?

I have a main menu for a movie kiosk, I can type a number (in this case 5) and it will take me to an admin menu. The problem is the admin menu has a different set of cases and when I enter a number to access a case from the admin menu it just takes…
T Dizzle
  • 69
  • 7
2
votes
1 answer

In which case should I use System.in.close()?

when I am reading the code of opentsdb: try { System.in.close(); // Release a FD we don't need. } catch (Exception e) { log.warn("Failed to close stdin", e); } After searching this question on the Internet, I can't find a suitable answer.…
Smallnine
  • 165
  • 7
2
votes
2 answers

NoSuchElementException on reopening the scanner within a method

Here's a reduced version of the code that's throwing the exception. static String s1; static String s2; static void getString(String s) { Scanner sc = new Scanner(System.in); s = sc.nextLine(); sc.close(); } public static void…
2
votes
0 answers

How to get console input for different threads in java?

when I tried to get console input from both main thread and thread I created, the console input can only be retrieved by one thread, either main thread or new thread. code as follow: public static void main(String[] args) { try …
Owen Lee
  • 21
  • 2
1
2
3
12 13