How to open a file when clicked on a java application?

0

I made a Java application and want to open a certain type of file in it, as with NetBeans, that is when a person clicks the ".java" file it opens in NetBeans (or another IDE that accepts this type of file).
However, even though I configure the file to open in my application, when it opens, its content does not appear in my application. Is there any java command to do this? A +

EDITED:

It's fine, but I can not do this well. I know how to open a file (I already have a method for this), but I can not call it in by passing the path because it gives error.

follow the code:

// essa é uma das minhas classes ,é ela que é chamada e possui todos os componentes visuais
public static void main(  String args[]) {

public void run() {
                new Programa().setVisible(true);
                  if(args.length > 0) {
                        try {
                      MetodoAbir(args[0])





            }catch(Exception erro) {

            }

        }

But of the error says that the method can not be "refenrenciado by static contex". This happens even if I put a method without parameter, or I can not call the methods there. I have also tried to create a global variable and to play the value args [0] on it to pass to the method in another location but also the same error.

    
asked by anonymous 28.07.2016 / 14:08

1 answer

0

When you open the application you have to check if no parameters have been passed to your program.

import java.io.File;

public class SeuPrograma {
    public static void main(String[] args) {
        if(args.length > 0) {
            File file = new File(args[0]);

            // Abra seu arquivo
        }
    }
}
    
28.07.2016 / 15:12