我的proccesos.txt有这个
1,500,600
2,300,800
3,800,1000
4,200,5000
我在这里尝试做的是将procesos.txt插入到一个2d数组中,该数组将显示为4行,包含3列但没有使用comamas
这是我在buttom上的代码
`
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\Users\\Ifrahim\\Desktop\\Procesos.txt"));
br2 = new BufferedReader(new FileReader("C:\\Users\\Ifrahim\\Desktop\\Procesos.txt"));
int lines = (int) br2.lines().count();
myArr = new int[lines][3];
String[] lineArray = null ;
while ((sCurrentLine = br.readLine()) != null) {
lineArray=sCurrentLine.split(",");
System.out.println(Arrays.toString(lineArray));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
`
答案 0 :(得分:0)
int line = 0;
while((sCurrentLine = br.readLine()) != null){
String[] tmp = sCurrentLine.split(",");//split the line up into its separate values
for(int i = 0 ; i < 3 ; i++)
myArr[line][i] = Integer.parseInt(tmp[i]);
//convert the values into integers and insert them at the matching position
//in the array
line++;
}