0

I have a console application where I need to read the console inputs as separated by line instead of separated by spaces. Is this possible?

public static void main(String[] args) {

Here the args is a string array and each console input separated by a space will be a separate member in args[]. I need to avoid this. For example , if the input is

word1 word2
line2
line3

i need to read it as

args[0] = word1 word2
args[1] = line2
args[2] = line3
afxgx
  • 129
  • 4
  • 11
  • 1
    A question very similar to http://stackoverflow.com/questions/743454/space-in-java-command-line-arguments – AurA Jul 19 '13 at 04:49

1 Answers1

0

After the first line the input becomes part of stdin. You could read remaining lines using Java's Scanner api

Scanner in = new Scanner(System.in);

See Some detailed examples or SO question How can I read input from the console using the Scanner class in Java?

Using this, you could re-create arguments and pass it to a another method.

Community
  • 1
  • 1
Jayan
  • 16,628
  • 12
  • 79
  • 131