Ecrire dans un fichier
Résolu
zmandar
-
flo13142 Messages postés 71 Date d'inscription Statut Membre Dernière intervention -
flo13142 Messages postés 71 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
svp je veux que vous m 'aidez a corriger ce code je ne sais pas pourquoi il ne me permet pas d 'écrire dans le troisième fichier lorsque il fait le test si il est true il faux ecrire ce ligne dans le fichier 3
svp je veux que vous m 'aidez a corriger ce code je ne sais pas pourquoi il ne me permet pas d 'écrire dans le troisième fichier lorsque il fait le test si il est true il faux ecrire ce ligne dans le fichier 3
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package basedonné; import java.util.Scanner; import java.io.*; public class Main { /** * @param args the command line arguments */ public static void main(String arg[]) throws IOException { attribut a1 ; attribut a2 ; a1=new attribut ("nom","String",15); a2=new attribut ("cin","int",12); relation R1; R1=new relation("E1",a1,a2) ; relation R2; R2=new relation("E2",a1,a2); a1.insert1(a2); a1.insert2(a2); File fichier = new File("C:\\R3.txt") ; BufferedWriter out = new BufferedWriter(new FileWriter(fichier, true)); out.close() ; String fichier1 ="R1.txt"; String fichier2 ="R2.txt"; String fichier3 ="R3.txt"; boolean b=copierPremiereLigneCommune(fichier1,fichier2,fichier3);} public static String premiereLigne(String fichier) throws FileNotFoundException { Scanner sc = new Scanner(new File(fichier)); String s = sc.nextLine(); sc.close(); return s; } /** * @param fichier1 fichier dont on lit la première ligne * @param fichier2 fichier dont on lit la première ligne * @param fichier3 fichier où l'on écrit la première ligne * @return false si l'opération a générée une exception, true sinon */ public static boolean copierPremiereLigneCommune(String fichier1, String fichier2, String fichier3) { String ligne1,ligne2; try { ligne1 = premiereLigne(fichier1); ligne2 = premiereLigne(fichier2); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } if (ligne1.equals(ligne2)) { try { FileOutputStream fos = new FileOutputStream("R3.txt"); OutputStreamWriter osw = new OutputStreamWriter(fos,"ISO-8859-1");//ou autre encodage type UTF-8 PrintWriter pw = new PrintWriter(osw); pw.print(ligne1); pw.close(); osw.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; } }
A voir également:
- Ecrire dans un fichier
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Fichier rar - Guide
- Fichier .dat - Guide