Java - Possible main method arguments in windows

Duke :

I wondered whether there was any connection between the main method's parameter String[] args and the possibility of opening files with a specified program. Considering that I wrote a simple program that writes down every String of args, then opened some files with this program (I am using windows).
This is what happened:
No matter what kind of file I opened with my program (right click -> open with...), argscontained only one String which was the file's complete path.
When I ran the program on itself, args was of length 0.

Now my question is: are there any other Strings that might be contained in args or would the following code always work without doubt? (I want to use this on windows, not play around with it like java MyProgram 1 2 3 "test"

public static void main(String[] args) {

    initProgram();

    if (args.length != 0) {            //file opened with program
        loadFile(new File(args[0]));
    }
}

Thank you for your answers and please be patient with my english.

Duke :

Just like Marcos Vasconcelos assumed: by opening multiple files at once args will contain all the files' paths tried to open, so args can be larger than just one String. Its length depends on the amount of files that want to be opened with the program.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=83008&siteId=1