SAE21_2022/FileImport.java

41 lines
1.2 KiB
Java
Raw Permalink Normal View History

import javax.swing.*;
import java.io.File;
2023-04-28 20:26:14 +02:00
/**
* La classe FlieImport a pour but d'aller chercher un fichier a ouvrir sur l'ordinateur via un JFileChooser
2023-04-28 20:26:14 +02:00
* @version 1.1
* @author Matthis Fauvet
*/
public class FileImport {
private String ce_chemin;
2023-04-28 19:17:35 +02:00
/**
* Constructeur ou l'on établit seulement
*/
public FileImport(){
this.ce_chemin = "";
2023-04-28 19:17:35 +02:00
}
2023-04-28 20:37:19 +02:00
/**
* méthode qui va permettre d'ouvrir un explorateur de fichier afin de choisir un fichier.
* Cette fonction renvoir le chemin d'accès de ce fichier.
2023-04-28 20:37:19 +02:00
*/
public String Parcours(){
JFileChooser fileChooser = new JFileChooser();
2023-04-28 19:17:35 +02:00
try {
int option = fileChooser.showOpenDialog(null);
if (option == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
this.ce_chemin = selectedFile.getAbsolutePath();
} else {
System.out.println("Aucun fichier sélectionné");
}
} catch (Exception e) {
System.out.println("Voici l'eereur rencontrée: " + e.getMessage());
this.ce_chemin = "";
}
2023-04-28 19:17:35 +02:00
return this.ce_chemin;
}
2023-04-28 19:17:35 +02:00
}