Posted By

nazymko on 03/04/13


Tagged

java shoot one


Versions (?)

One shoot code


 / Published in: Java
 

Just do ti!

  1. public void actionPerformed(ActionEvent e) {
  2. JFileChooser fileselector = new JFileChooser();
  3. fileselector.setName("Export xml file");
  4. fileselector.accept(new File("gameplan.xml"));
  5. fileselector.showSaveDialog(context);
  6.  
  7. File selectedFile = fileselector.getSelectedFile();
  8. if (selectedFile != null) {
  9. System.out.println(selectedFile.toString());
  10.  
  11. if (!selectedFile.exists()) {
  12. try {
  13. selectedFile.createNewFile();
  14. } catch (IOException e1) {
  15. JOptionPane.showInternalMessageDialog(context,
  16. "Ooops , I not can create the file ["
  17. + selectedFile.toString() + "]");
  18. }
  19.  
  20. }
  21. FileWriter writer;
  22. try {
  23. writer = new FileWriter(selectedFile);
  24. String xml = context.toXml();
  25. writer.write(xml);
  26. writer.close();
  27. } catch (IOException e1) {
  28. JOptionPane.showInternalConfirmDialog(context,
  29. "Somethink a going wrong wit h IO process");
  30. System.err.println(e1.getStackTrace());
  31. }
  32.  
  33. }
  34. }
  35. });

Report this snippet  

You need to login to post a comment.