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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| ArrayList<Country> countries = new ArrayList<Country>();
String countryName;
String population;
String surface;
String fichier1 = "country_codes_iso.csv";
String fichier2 = "POP.csv";
String fichier3 = "rawdata_2147.txt";
BufferedReader br1 = null;
BufferedReader br2 = null;
BufferedReader br3 = null;
{
try {
File f1 = new File(fichier1);
File f2 = new File(fichier2);
File f3 = new File(fichier3);
br1 = new BufferedReader (new FileReader(f1));
br2 = new BufferedReader (new FileReader(f2));
br3 = new BufferedReader (new FileReader(f3));
String line1 = null;
String line2 = null;
String line3 = null;
while ((((line1 = br1.readLine())!= null)) && ((line2 = br2.readLine())!=null) && ((line3 = br3.readLine())!=null)){
String[] champLine1 = line1.split(","); // je lis les champs dans le fichier 1 (séparés par des virgules)
String[] champLine2 = line2.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
String[] champLine3 = line3.split("\t"); // je lis les champs dans le fichier 3 (séparés par des tab)
countryName = champLine1[0]; // le pays est en première position
surface = champLine3[2];
//if (champLine2[2].equals(countryName)){
population = champLine2[4];
//}
if (line3.contains(countryName)){
surface = champLine3[2];
}
Country country = new Country(countryName,population,surface);
countries.add(country);
}
}
catch (Exception e){
e.printStackTrace();
}
finally {
try {
br1.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
br2.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
br3.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} |