Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Command line argument

Thread view: 
joe - 02 Dec 2007 23:19 GMT
Hi

I was if  " -v " flag means anything in comand line argument. In our
project they told us to right the comman line argument in this
forum...

java WorPairCounter -vN FileName

And N stands for either 1 or 2 . So were are asked to check if N is 1
or 2 , so is there any way to check it ??
Owen Jacobson - 02 Dec 2007 23:22 GMT
> Hi
>
[quoted text clipped - 6 lines]
> And N stands for either 1 or 2 . So were are asked to check if N is 1
> or 2 , so is there any way to check it ??

Command line arguments are passed as-tokenized to the main method as a
string array.  In your case, you'd get the following as your args array:

{"-v1", "FileName"}
or
{"-v2", "FileName"}

-o
Arne Vajhøj - 02 Dec 2007 23:53 GMT
> I was if  " -v " flag means anything in comand line argument. In our
> project they told us to right the comman line argument in this
[quoted text clipped - 4 lines]
> And N stands for either 1 or 2 . So were are asked to check if N is 1
> or 2 , so is there any way to check it ??

    public static void main(String[] args) {
        if(args.length == 2) {
            int version = 0;
            String fnm = null;
            for(int i = 0; i < args.length; i++) {
                if(args[i].startsWith("-v")) {
                    version = Integer.parseInt(args[i].substring(2));
                } else {
                    fnm = args[i];
                }
            }
            if(version > 0 && fnm != null) {
                System.out.println("version=" + version);
                System.out.println("fnm=" + fnm);
            } else {
                System.out.println("Usage: java WPCr -vn filename");
            }
        } else {
            System.out.println("Usage: java WPC -vn filename");
        }
    }

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.