import java.io.File; import javax.swing.filechooser.FileFilter; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JFileChooser; public class Main { public static void main(String[] args) throws IOException { FileFilter ff = new FileFilter(){ public boolean accept(File f){ if(f.isDirectory()) return true; else if(f.getName().endsWith(".txt")) return true; else return false; } public String getDescription(){ return "TXT files"; } }; RecupererPath(ff); } public static String RecupererPath(FileFilter type) throws IOException { JFileChooser dialogue = new JFileChooser(new File(".")); dialogue.addChoosableFileFilter(type); PrintWriter sortie; File fichier = null; new HelloWorldFrame(1); int i = dialogue.showOpenDialog(null); if (i== JFileChooser.APPROVE_OPTION) { new HelloWorldFrame(2); fichier = dialogue.getSelectedFile(); sortie = new PrintWriter(new FileWriter(fichier.getPath(), true)); sortie.close(); } new HelloWorldFrame(3); return fichier.getPath(); } }
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question