Advertisement
kyle1320

Untitled

Feb 16th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. public void saveToFile() {
  2.     FileDialog fileDialog = new FileDialog(this, "Save to File", FileDialog.SAVE);
  3.     fileDialog.setFilenameFilter(new FilenameFilter() {
  4.                     public boolean accept(File dir, String name) {
  5.                         return  name.length() > 4 &&
  6.                             name.substring(name.length()-4).equals(".spr");
  7.                     }
  8.                 });
  9.     fileDialog.setVisible(true);
  10.     File[] files = fileDialog.getFiles();
  11.  
  12.     if (files.length != 0) {
  13.         String path = files[0].getCanonicalPath();
  14.         if (!path.substring(path.length()-4).equals(".spr"))
  15.             path = path + ".spr";
  16.                
  17.         try {
  18.             File fout = new File(path);
  19.             // write to the file
  20.         } catch (Exception e) {
  21.             e.printStackTrace();
  22.             JOptionPane.showMessageDialog(this, "Error saving file!", "Error", JOptionPane.ERROR_MESSAGE);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement