files-input from console application
Hello,
I want the program to combine 2 txt files and create a new one. The thing is that I cannot find anywhere how to declare the files together with the app.
For example: java <name> -q <file1> -w <file> 2
How could this be done?
Is this even possible?
Thanks in advance.
Re: files-input from console application
Quote:
how to declare the files together with the app.
You can use the command line to pass any arguments to the program. What is passed is completely up to you.
java <CLASSNAME> <any args that you want here>
To see what is passed and how to get it, write a simple program that prints out the args array that the main() method receives.
Then call it with a lot of different arguments and see what it prints out.
Re: files-input from console application
Thanks for this. I started with something...
...and I stuck again:
The compiler recognizes (args[0] = "-i") as String an not as boolean.( in an if (~))
Any ideas about what am I doing terribly wrong?
Re: files-input from console application
Quote:
The compiler recognizes (args[0] = "-i") as String an not as boolean.
The args from the command line are contained in the String array: main(String[] args)
args[0] = "-i"
Is an assignment (=) statement. Use the equals() method for comparing Strings
Re: files-input from console application
:O I will try == and then the method you advised..
thanks.. It was really in front of me..
Re: files-input from console application
Use the equals() method for Strings NOT ==
Re: files-input from console application
:O I will try == and then the method you advised..
thanks.. It was really in front of me..
Re: files-input from console application
Quote:
Originally Posted by
roronoa485
:O I will try == and then the method you advised..
thanks.. It was really in front of me..
You have already been advised that it's wrong to use ==
Why ask on a forum if you're not willing to learn from the responses?
db