LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   java - how do you input from the command line (https://www.linuxquestions.org/questions/programming-9/java-how-do-you-input-from-the-command-line-253080/)

zeviddalop 11-09-2004 11:23 PM

java - how do you input from the command line
 
i'm kinda perplexed, i've got a project for school where we're supposed to write a driver to allow piped input/output : for ex, driver < inputFile1 > outputFile but for a variety of input files. i can't figure out how to code this without specifically including the input file in the driver. can anyone help?

zeviddalop 11-10-2004 12:02 AM

no worries, got it figured out.

rjlee 11-10-2004 06:26 AM

The answer to the question is to use the System.in and System.out streams.

Please post the answers to your questions if you find out what they are; that way other people can benefit from your insight.

Well done on fixing it, though :)

ta0kira 11-10-2004 07:29 AM

I think zeviddalop meant take arguments when calling 'java' to exec the program. If that is the case, it is almost like C++:

class App
{
public static void main(String[] args)
{
//all command line arguments are stored in 'args'; just use it like a normal array
//(the exec name isn't given in [0], unlike C++)
}
}

eantoranz 11-10-2004 11:59 AM

If i were to read by lines, I would do:
Code:

BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
keyboard.readLine();



All times are GMT -5. The time now is 04:59 AM.