Pregunta

In my program I am making a .csv file and then before exiting I want the .csv file to open up. I tried to use this code: Desktop.getDesktop().open( "d:\\Output.csv" ); but it gives an error saying: cannot find symbol. Symbol: variable Desktop

(I am doing this inside a button, before it exits the program) Code:

System.out.println("Done!");
    Done.setText("Done!");
    Desktop.getDesktop().open( "d:\\Output.csv" );



    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch(InterruptedException ex) {
                ex.printStackTrace();
            }                
            System.exit(0);
        }
    }).start();
¿Fue útil?

Solución 2

Replace Desktop.getDesktop().open( ”d:\\Output.csv“ ); by Desktop.getDesktop().open(new File("d:\\Output.csv"));

Otros consejos

Check if this isn' t just a missing import of java.awt.Desktop.

Make a method, for e.g fileUpload

public fileUpload() {
        File file = new File("c:\\file_name.csv");
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

then, try out once using this method and implement it on your code. Now see what's going on!

new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch(InterruptedException ex) {
                ex.printStackTrace();
            }                
            System.exit(0);
        }
    }).start();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top