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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Fichier {
public void lire_Fichier (String p_fich) throws IOException {
BufferedReader w_lecture = null;
String ligne;
try {
w_lecture = new BufferedReader (new FileReader(p_fich));
}
catch (FileNotFoundException exc) {
System.out.println("Fichier inexistant !!!");
}
while ((ligne = w_lecture.readLine()) != null)
System.out.println(ligne);
w_lecture.close();
}
public void ecrire_Fichier (String p_fich, String p_commentaire, boolean ajout) throws IOException {
try {
FileReader w_r = new FileReader(p_fich);
FileWriter w_c = new FileWriter(p_fich, ajout);
w_c.write(p_commentaire);
w_c.flush();
w_c.close();
}
catch (FileNotFoundException exc) {
System.out.println("fichier inexistant !!!");
}
}
public boolean supprimer_Fichier (String p_fich) throws IOException {
boolean resultat = true;
try {
FileReader w_r = new FileReader(p_fich);
resultat = true;
}
catch (FileNotFoundException exc) {
System.out.println("fichier inexistant !!!");
resultat = false;
}
finally {
return resultat;
}
} |
Partager