Pour te placer sur le repertoire courant
JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.dir")));
Ou encore
JFileChooser chooser = new JFileChooser(new File("."));
Pour enregistrer ton fichier, tu peux créer un fichier temporaire et enregistrer ce dernier sous le répertoire choisit depuis le JFileChooser
1 2 3 4 5 6 7 8 9 10 11 12
| File tmp = null;
try {
tmp = File.createTempFile("tmp", "");
}
catch (FileNotFoundException fnfe) { // ... }
catch (IOException ioe) { //... }
int choice = chooser.showSaveDialog(null);
if(choice == JFileChooser.APPROVE_OPTION)
tmp.renameTo(chooser.getSelectedFile()); |
Partager