jj1k
Messages postés30Date d'inscriptionjeudi 8 juin 2017StatutMembreDernière intervention 3 septembre 2017
-
22 juin 2017 à 14:35
Bonjour
j'ai un fichier txt avec 7 champs, àpartir de se fichier je veux creer un autre fichier avec 9 champs (les deux champs ajouter sont calculer apartir des champs existant)
j'ai commencé avec ce code
package exmpl1;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
public class A1 {
static String Newligne = System.getProperty("line.separator");
public static void main(String[] args) throws Exception {
Class.forName("org.relique.jdbc.csv.CsvDriver");
//String csvFile = "C:/Users/RIM/Desktop/pr02.txt";
int EM=15;
int L=90;
String csvFile = "d:/t1.txt";
String csvFile1 = "C:\\csv\\csv1.txt";
List<LineFile> list;
try {
list = ListFromTXT(csvFile);
TXTFromList(list, csvFile1);
List<LineFile> list1 = ListFromTXT(csvFile1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void TXTFromList(List<LineFile> liste_files, String file_name)
throws IOException {
File fichier_clt = new File(file_name);
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(
fichier_clt, true));
bufferedWriter.append("id,X,Y,capacite,charge,alpha,beta,alpah1,beta1");
for (LineFile lfile : liste_files) {
String cont = "";
cont = cont + lfile.getAid() + ",";
cont = cont + lfile.getAttribute2() + ",";
cont = cont + lfile.getAttribute3() + ",";
cont = cont + lfile.getAttribute4() + ",";
cont = cont + lfile.getAttribute5() + ",";
cont = cont + lfile.getAttribute6() + ",";
cont = cont + lfile.getAttribute7() + ",";
cont = cont + lfile.getAttribute8() + ",";
cont = cont + lfile.getAttribute9() + ",";
cont = cont + Newligne;
bufferedWriter.write(cont);
}
bufferedWriter.close();
}
public static List<LineFile> ListFromTXT(String file_name)
throws IOException {
BufferedReader br = null;
String line = "";
ArrayList<LineFile> files = new ArrayList<LineFile>();
try {
br = new BufferedReader(new FileReader(file_name));
int cpt = 0;
Integer c1 = Integer.valueOf(15);
Integer c2 = Integer.valueOf(30);
while ((line = br.readLine()) != null) {
if (cpt > 0 ){
String[] ls = line.split(",");
LineFile lineFile = new LineFile();
lineFile.setAttribute1(ls[0]);
lineFile.setAttribute2(ls[1]);
lineFile.setAttribute3(ls[2]);
lineFile.setAttribute4(ls[3]);
lineFile.setAttribute5(ls[4]);
lineFile.setAttribute9(ls[5] );
lineFile.setAttribute7(ls[6]);
// lineFile.setAttribute8(ls[7]);
files.add(lineFile);
}
cpt++;
}
return files;
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
}
}
Maintenant je veux que la valeur du nouveau champs 8 des lignes 1.2.3.4.5.6.7 et 8 est egalé à la valeur du champs 6 des lignes 17,18,19,20,21,22,23 et 24 - la valeur déclaré Integral C1 . et la valeur du nouveau champs 8 des lignes 25,26,27,28,29,30,31,32 et33 est egalé à la valeur du champs 6 des ligne 9,10,11,12,13,14,15 et 16 + la valeur Integral C2 .
Comment je peux le faire ?
Merci d'avance