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
|
public static String readFile(String fichier) throws IOException, FileNotFoundException {
try {
// 1 - Création de la ressource
FileReader reader = new FileReader(fichier);
try {
// 2 - Utilisation de la ressource
StringBuffer buffer = new StringBuffer();
char[] cbuf = new char[2048];
int len;
while ( (len = reader.read(cbuf)) > 0 ) {
buffer.append(cbuf, 0, len);
}
return buffer.toString();
while ((ligne = lecteurAvecBuffer.readLine()) != null)
} finally {
// 3 - Libération de la ressource
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
return "Erreur dans la lecture du fichier.";
}
} |
Partager