0

When my Java file-processing program is opened by an Open With... command, or is set as a file's default program, how do I handle the file that opened it.

Is it passed as a command line argument? In what format?

And how about programs, wrapped in an .exe wrapper, or compiled with an AOT compiler?

Mordechai
  • 15,437
  • 2
  • 41
  • 82

3 Answers3

1

Create an executable of your Java File processing program. Please read this-creating executable file if you want to know, how to create executable?

In command line, you may say: executable FileName.ext

FileName.ext will be available in your main program's args[0] attribute. i.e.

       public static void main(String[] args){
           String fileName = args[0];
        }
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • I get `'executable' is not recognized as an internal or external command` etc., . – Mordechai Oct 28 '12 at 03:44
  • @M.M.: How did you create the executable file? By executable, I meant the executable fine name. Please read this-[**creating executable file**](http://dasha.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html) if you want to know, how to create executable? By the way, I see you have already accepted one answer. Are you still looking for some solution? – Yogendra Singh Oct 28 '12 at 04:03
1

Launch the app. with Java Web Start and declare an interest in the file-type within the launch file (JNLP).

The path to the File will be passed as a String as the 2nd argument to the main. The 1st argument will be either -edit/open (I forget) or -print.

And how about programs, wrapped in an .exe wrapper, or compiled with an AOT compiler?

How about asking that on a separate question? If deploying with JWS, we would use Jar(s).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

You should receive the file's path as an argument in main().

See Using command-line argument for passing files to a program (maybe duplicated?)

Community
  • 1
  • 1
mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81