My problem, I have a txt file which look like this :
CA-ADAPT-BAT18AH;CABLE ADAPTATION POUR CHARGER BATTERIE 18Ah
OP-CBL-PX738;CABLE TM 220V BUL 738 4.5M
OP-PAN-CABLE-Y;CABLE Y POUR PIV MINI & MAXI (1 FEM - 2 MAL)
OP-PAN-DATA;Câble datacom
OP-TMSSA-DATA;Câble datacom
OP-SOL-CABLE-1;CABLE POUR PANNEAU SOLAIRE : BOITIER VERS PIV
There is 2 information's per line, separated by an ";"
In my code java I have a var like "String[][] info = new String[25][2];"
I just want to read the whole file an put the 1st information of the 1st line in info[0][0] and the 2nd information of the 1st line in info[0][1]. And do the same process for the rest of the data of the file.
So here is my code :
public class Function {
public static String[][] getCable() throws FileNotFoundException {
String delim = ";";
String line = null;
String[][] info = new String[25][2];
String[] temp;
int i = 0,j = 0,a = 0,b = 0;
String filePath = "C:/Users/ogh/Desktop/Appli Java/cable.txt";
Scanner scanner = new Scanner(new File(filePath));
for (i = 0; i < 25; i++){
for (j = 0; j < 2; j++){
if (j == 0) info[i][j] = "ID : ";
if (j == 1) info[i][j] = "Descr. : ";
}
j = 0;
}
while (scanner.hasNextLine()) {
line = scanner.nextLine(); // get 1 line
temp = line.split(delim); // split that line in 2 with ";"
info[b][a] = info[b][a] + temp[a];
info[b][a+1] = info[b][a+1] + temp[a+1];
if (a >= 1) {
a = 0;
b++;
}
}
scanner.close();
for (i = 0; i < 25; i++){
System.out.println(i+ "-> Info :"+ info[i][0]+"\t"+info[i][1]);
}
return info;
}
public static void main(String args[]) throws Throwable {
getCable();
}
}
And the output I get : All the Id are in the info[0][0] and all the description are in the info[0][1]
Thanks.
a++in your code.