Results 1 to 8 of 8
  1. #1
    roronoa485 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: files-input from console application

    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.

  3. #3
    roronoa485 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default 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?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: files-input from console application

    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

  5. #5
    roronoa485 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: files-input from console application

    :O I will try == and then the method you advised..
    thanks.. It was really in front of me..

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: files-input from console application

    Use the equals() method for Strings NOT ==

  7. #7
    roronoa485 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: files-input from console application

    :O I will try == and then the method you advised..
    thanks.. It was really in front of me..

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default Re: files-input from console application

    Quote Originally Posted by roronoa485 View Post
    :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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Console input issue
    By gaguevaras in forum New To Java
    Replies: 3
    Last Post: 05-01-2011, 03:42 AM
  2. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 09:32 PM
  3. how to take input from console in jsp
    By veena in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 04:39 AM
  4. How to read input from console
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-16-2008, 10:57 PM
  5. How to read input from the console
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-06-2008, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •