Lire d’un fichier
(une ligne à la fois)
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
public class copieLignes {
public static void main(String[] args) throws IOException {
BufferedReader streamEntree = null;
PrintWriter streamSortie = null;
try {
streamEntree = new BufferedReader(new FileReader("xanadu.txt"));
streamSortie = new PrintWriter(new FileWriter("characteroutput.txt"));
String l;
while ((l = streamEntree.readLine()) != null) {
streamSortie.println(l);
}
} finally {
if (streamEntree != null) {
streamEntree.close();
}
if (streamSortie != null) {
streamSortie.close();
}
}
}
}