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
| import java.io.*;
public class CompterLigne {
public File fichier;
public FileWriter fluxOut;
public CompterLigne(String nomFichier) throws FileNotFoundException, IOException{
fichier=new File(nomFichier);
fluxOut=new FileWriter(fichier);
}
public void ajouter(String texte) throws IOException{
fluxOut.write(texte);
fluxOut.flush(); //Pour envoyer le buffer dans le fichier
}
public static void main(String [] arg) throws FileNotFoundException, IOException{
CompterLigne test=new CompterLigne("test2.txt");
test.ajouter("Ma phrase");
}
} |
Partager