File temp=null;
FileWriter fileWriter=null;
PrintWriter printWriter=null;
try
{
temp = File.createTempFile("temp-file-name", ".txt");
String rutaTemp=temp.getAbsolutePath();
fileWriter=new FileWriter(rutaTemp, true);
printWriter=new PrintWriter(fileWriter);
printWriter.println(txtContenido.getText());
Desktop.getDesktop().open(temp);
}
catch (IOException e) {
JOptionPane.showMessageDialog(thisJFrame, "No se puede abrir el programa.", "Error", JOptionPane.ERROR_MESSAGE);
}
finally
{
if(printWriter!=null)
{
printWriter.close();
}
if(fileWriter!=null)
{
try
{
fileWriter.close();
}
catch(Exception ex)
{
JOptionPane.showConfirmDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}