Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void saveToFile() {
- FileDialog fileDialog = new FileDialog(this, "Save to File", FileDialog.SAVE);
- fileDialog.setFilenameFilter(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.length() > 4 &&
- name.substring(name.length()-4).equals(".spr");
- }
- });
- fileDialog.setVisible(true);
- File[] files = fileDialog.getFiles();
- if (files.length != 0) {
- String path = files[0].getCanonicalPath();
- if (!path.substring(path.length()-4).equals(".spr"))
- path = path + ".spr";
- try {
- File fout = new File(path);
- // write to the file
- } catch (Exception e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(this, "Error saving file!", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement