Вот пример структуры файла:
Код: Выделить всё
> 2.0 5.0 3.5
>
> 5.2 0.5 4.8
>
> 1.0
>
> 2.5
Ниже приведен код, который я написал на данный момент:
Код: Выделить всё
import java.io.*;
public class MainProg {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("info.txt");
BufferedReader br = new BufferedReader(fr);
String nums;
int count = 0;
int lineNo = 0;
while ((nums = br.readLine()) != null) {
String[] numbers = nums.split(" ");
double[][] ball = new double[lineNo][];
if (numbers.length == 3) {
for (int i = 0; i < numbers.length; i++) {
double[][] box = new double[lineNo][i];
box[lineNo][i] = Double.parseDouble(numbers[lineNo]);
lineNo++;
System.out.println(box[i] + " ");
}
} else {
while (numbers.length == 1 && ((nums = br.readLine()) != null)) {
int p = 0;
ball[count][p] = Double.parseDouble(numbers[count]);
p++;
count++;
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ent-arrays
Мобильная версия