1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| JFileChooser saveChoose = new JFileChooser(); //new fileChooser
saveChoose.setAcceptAllFileFilterUsed(false);
FiltreSimple[] fs = new FiltreSimple[2];
fs[0] = new FiltreSimple("Java Files",".java");
fs[1] = new FiltreSimple("Text Files",".txt");
for(FiltreSimple f : fs){
saveChoose.addChoosableFileFilter(f);
}
saveChoose.setCurrentDirectory(new File("."));
int resultatSave = saveChoose.showSaveDialog(saveChoose);
if(resultatSave == saveChoose.APPROVE_OPTION){
System.out.println("1. Start saving current file");
try{
String f = textPaneArea.getText(0,10);
BufferedWriter bfwriter = new BufferedWriter(new FileWriter(f));
System.out.println("2. Buffer created");
try {
System.out.println("3. File name to save = "+f);
bfwriter.write(textPaneArea.getText(), 0, textPaneArea.getText().length());
System.out.println("4. Saving current file completed");
}finally {
bfwriter.close();
System.out.println("5. Buffer is closing");
}
} catch (Exception e1) {
e1.printStackTrace();
System.out.println("6. Stop ! error of save");
}
}
if(resultatSave == saveChoose.CANCEL_OPTION){
System.out.println("Saving canceled");
} |