• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

quick stupid java question

NeoMadHatter

Platinum Member
how can i just read input from the first command line input?

java Program 2 4 5 inputfile > out

i want to be able to get the following:

x = 2
y = 4
z = 5

and then read the rest of the input from the inputfile
and then redirect the output of the program to the file "out" as it shows i can.
 
I'm rusty on this, but it seems to me like your 2 4 5 should be in the args array with that usage. Grab your 2,4,5 from there and assign the values to your x, y, and z?

I think you really want:
java Program 2 4 5 < inputfile > outputfile
What you do in the program is irrelevant as long as you print out to the screen what you want, with > outputfile it will go to the outputfile instead of the screen, and with < the input will be taken from your inputfile. I'm too rusty on my console Java IO to help you out w/ the actual commands though.

HTH
 
The standard Java main() method takes one parameter, a String array which contains all arguments which were supplied on the command line. By looking at the length of the String array you will know how many arguments the user passed your application, you can then access each of these arguments as required and process as required.

Example...

public static void main(String[] arguments) {
// get the total number of arugments passed
int n = arguments.length();

//get the nth argument (substitute n with the parameter you want)
String myString = arguments[n];

}

If this isn't clear do a seach in Google for a begineer Java tutorial.

Cheers.
 
Back
Top