Comparaison de 2 fichiers texte (pb boucle while je pense)
tomski
Messages postés48Date d'inscriptionmercredi 24 mars 2004StatutMembreDernière intervention24 décembre 2009
-
7 mai 2009 à 17:15
tomski
Messages postés48Date d'inscriptionmercredi 24 mars 2004StatutMembreDernière intervention24 décembre 2009
-
11 mai 2009 à 12:20
Bonjour,
Jessaye de comparer 2 fichiers texte ligne par ligne.Chaque ligne est decoupee (split(";")) et chaque mot est stocké dans un array.
Ensuite je compare le contenu des array, en fonction des "colonnes" ou se trouvent les elements a comparer (au cas ou les champs a comparer ne soient pas dans les memes colonnes dans les 2 fichiers...)
Ca split, ca stocke. Mais le hic c'est que a la comparaison, il reste bloque sur la premiere ligne (voir contenu du fichier de LOG): il affiche 4 fois la meme ligne pour la ligne 1, alors que la ligne 2 varie bien au fur et a mesure de la boucle.
Ca doit venir de ma boucle
public static void main(String[] args) {
System.out.println("in MAIN");
CINTEL cintel = new CINTEL();
cintel.setSize(600,600);
cintel.setTitle("ROBOT Remplissage fichier Excel");
ImageIcon img= new ImageIcon("smiley.gif");
cintel.setIconImage(img.getImage());
//ajout du panel daffichage graphique
cintel.getContentPane().add(new MyComponent());
cintel.setDefaultCloseOperation(EXIT_ON_CLOSE);
cintel.setVisible(true);
}//end main()
public void showDialog2(){
System.out.println("in SHOWDIALOG 2");
d_choosefile.setVisible(false);
d_choosecolumns = new JDialog(this, "Choix des colonnes...", true);
JPanel p_col = new JPanel();
JLabel lbcol1 = new JLabel("Champs fichier 1 (n° de ND)");
JLabel lbcol2 = new JLabel("Colonnes à remplir fichier 2");
JLabel lbcol3 = new JLabel("Champs fichier 2 (n° de ND)");
JLabel lbcol4 = new JLabel("Champs fichier 1 (Date)");
JLabel lbcol5 = new JLabel("Champs fichier 2 (Date)");
//JLabel ls3 = new JLabel("Fichier LOG");
//String[] col1Strings = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
//Create the combo box, select item at index 4.
JComboBox col1List = new JComboBox(col1Strings);
col1List.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("in NEXT >>");
JComboBox cb = (JComboBox)e.getSource();
st_col1 = (String)cb.getSelectedItem();
System.out.println("st_col1= "+ st_col1);
}
});
JComboBox col2List = new JComboBox(col1Strings);
col2List.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("in NEXT >>");
JComboBox cb = (JComboBox)e.getSource();
st_col2 = (String)cb.getSelectedItem();
System.out.println("st_col2= "+ st_col2);
}
});
JComboBox col3List = new JComboBox(col1Strings);
col3List.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("in NEXT >>");
JComboBox cb = (JComboBox)e.getSource();
st_col3 = (String)cb.getSelectedItem();
System.out.println("st_col3= "+ st_col3);
}
});
JComboBox col4List = new JComboBox(col1Strings);
col4List.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("in NEXT >>");
JComboBox cb = (JComboBox)e.getSource();
st_col4 = (String)cb.getSelectedItem();
System.out.println("st_col4= "+ st_col4);
}
});
JComboBox col5List = new JComboBox(col1Strings);
col5List.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("in NEXT >>");
JComboBox cb = (JComboBox)e.getSource();
st_col5 = (String)cb.getSelectedItem();
System.out.println("st_col5= "+ st_col5);
}
});
JButton btn_ok = new JButton("OK");
btn_ok.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("in OK >>");
LineComparator();
static class MyComponent extends JComponent {
MyComponent() {
System.out.println("in MYCOMPONENT()");
}//end MyComponent
}//end class MyComponent
public void LineComparator(){
System.out.println("in LineComparator");
//check ke les ND soient identiques (055232689 et 55232698 pas identiques!)
//check les dates 15-avr-09 et 15/04/2009 pas dientiques
// try {
// Open log file
// PrintWriter plog = new PrintWriter( new FileWriter( txtchoiceLog+ "Change.log"));
try{
System.out.println("dans le 1er TRY");
BufferedReader br1=new BufferedReader(new FileReader(txt_choice1.getText()));
BufferedReader br2=new BufferedReader(new FileReader(txt_choice2.getText()));
FileWriter fstream = new FileWriter("LOG.txt");
BufferedWriter out = new BufferedWriter(fstream);
try{
System.out.println("dans le 2eme TRY, les BUFFER sont lances");
String ligne1;
String ligne2;
int indexLigne=0;
arrayString1 = new String[10]; // a redimensionner avec le nombre de ligne exact !
arrayString2 = new String[10];
//while ((ligne1=br1.readLine())!=null){
while(true){
ligne1=br1.readLine();
//System.out.println("dans le 1er WHILE");
while ((ligne2=br2.readLine())!=null){
System.out.println("dans le 2eme WHILE");
String[] elements1 = ligne1.split(";");
//System.out.println("elements1" + elements1);
String[] elements2 = ligne2.split(";");
//System.out.println("elements2" + elements2);
for (int i = 0; i<elements1.length ; i++){
System.out.println("dans le FOR");
arrayString1[i] = elements1[i];
arrayString2[i] = elements2[i];
System.out.println("arrayString1[i]= " + arrayString1[i] + " arrayString2[i] = "+ arrayString2[i]);
}//end for
//for (int i = 0; i<arrayString1.length ; i++){
if(arrayString1[Integer.parseInt(st_col1)].compareTo(arrayString2[Integer.parseInt(st_col3)]) < 0){
//System.out.println("ON COMPARE LES DONNEES: arrayString1[Integer.parseInt(st_col1)] = " + arrayString1[Integer.parseInt(st_col1)] + " arrayString2[Integer.parseInt(st_col3)] = " + arrayString2[Integer.parseInt(st_col3)]);
//chaines identiques donc on renseigne la colonne