Open txt with java

1

I need to open a txt file but from the console but from an application that opens txt, in the event of the button you should open the txt as if you were opening from the operating system, I use GNU / linux (Debian)

If something serves you search the internet and I just found this and that was my adaptation to the code

try {
            ProcessBuilder p=new ProcessBuilder();
            p.command("/home/hp/Escritorio/ventas/reporte.txt");
            p.start();
        } catch (IOException ex) {
            Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
        }

but you send me an error

java.io.IOException: Cannot run program "/home/hp/Escritorio/ventas/reporte.txt": error=13, Permiso denegado
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

Thanks, I hope any help or the right way to do it

    
asked by MZ39720 26.11.2018 в 17:02
source

1 answer

0

If I do not understand correctly, you want a file to open with the application that is associated by default in the operating system. For example, that a txt file opens a text editor to edit that file, an mp3 that launches a player ... etc.

In Java, this is done with the class java.awt.Desktop :

Desktop dt= Desktop.getDesktop();
dt.open("path del fichero");
    
answered by 26.11.2018 / 17:19
source