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 75 76
|
public static String[] harvestFile () throws FileNotFoundException
{
String filePath = "c:\\test.txt";
Scanner scanner=new Scanner(new File(filePath));
int numLignes=0; // initialise le compteur de ligne
//on lit les deux premières lignes
while (numLignes<2)
{
String line = scanner.nextLine();
int num = Integer.parseInt(line); //convertir le string en integer
switch(numLignes)
{
case(0): nbreElem=num;break;
case(1): tpsTot=num;break;
}
numLignes ++;
}
String Recup_don[]=new String[nbreElem];
numLignes=0;
//int k=0;
while (scanner.hasNext())
{
Recup_don[numLignes]=scanner.nextLine();
numLignes++;
}
scanner.close();
return Recup_don;
}
public static double[][] CreerMatrice(String[] donnees_string, String[] classe) {
double matDonnees[][]=new double [nbreElem][2];
for(int i=0;i<donnees_string.length;i++)
{
String input = donnees_string[i];
Scanner s = new Scanner(input).useDelimiter(";");
int k=0;
matDonnees[i][k]=s.nextDouble();
k++;
matDonnees[i][k]=s.nextDouble();
classe[i]=s.next();
if(i<donnees_string.length)
{
s.close();
}
}
return matDonnees;
}
public static void main(String[] args) throws FileNotFoundException
{
String[] donnees_string=harvestFile();
String[] classe = new String[nbreElem];
double donnees[][]=CreerMatrice(donnees_string, classe);
} |