import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
class ReadClass {
FileReader fr;
BufferedReader br;
public ReadClass() {
try {
fr = new FileReader("E:\\111.txt");
br = new BufferedReader(fr);
} catch (IOException Ie) {
System.out.println("文件不存在!");
Ie.printStackTrace();
}
}
public void ReaderPrint() {
try {
int i = 0, max = 0;
int[][] NumberArray = new int[3][3];
String Read = br.readLine();
String[] strNumber = new String[3];
while (Read != null) {
strNumber = Read.split(" ");
for (int j = 0; j < strNumber.length; j++) {
NumberArray[i][j] = Integer.parseInt(strNumber[j]);
}
Read = br.readLine();
i++;
}
for (int k = 0; k < i; k++) {
for (int f = 0; f < 3; f++) {
System.out.print(NumberArray[k][f] + " ");
}
System.out.println();
}
max = NumberArray[0][0];
for (int i1 = 0; i1 < NumberArray.length; i1++) {
for (int j1 = 0; j1 < NumberArray.length; j1++) {
if (NumberArray[i1][j1] > max) {
max = NumberArray[i1][j1];
}
}
}
System.out.println("最大的数是:" + max);
br.close();
fr.close();
} catch (IOException Ie) {
System.out.println("文件读取失败!");
Ie.printStackTrace();
}
}
}
// 测试类
public class test {
public static void main(String[] arges) throws IOException {
ReadClass R = new ReadClass();
R.ReaderPrint();
}
}
源数据文件:
java 从文件中读取实数数据(三行三列),在控制台输出大的
import java.io.BufferedReader;import java.io.IOException;class ReadClass { FileReader fr;BufferedReader br;public ReadClass() { try { fr = new FileReader("E:\\\\111.txt");br = new BufferedReader(fr);} catch (IOException Ie) { System.out.println("文件不存在!");Ie.printStackTra...