You could do something like this.
It's just an example but a JOptionPane will popup with YES and NO. If you click YES, the file will open.
String fileName = "file.txt";
// File written. Open?
JOptionPane pane = new JOptionPane("file saved. Open file?");
Object[] options = new String[] { "YES", "NO" };
pane.setOptions(options);
JDialog dialog = pane.createDialog(new JFrame(), "File Saved");
dialog.show();
Object obj = pane.getValue();
int result = -1;
for (int k = 0; k < options.length; k++)
if (options[k].equals(obj)){
result = k;
String opt = Integer.toString(result);
// if YES
if(opt.equals("0")){
// Open file
Process p = Runtime.getRuntime().exec("cmd /c \""+fileName+"\"");
}else{
// do nothing
}
}
This opens the file:
You will need to import:
javax.swing.JOptionPane;
javax.swing.JDialog;