package io_operate;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class Fair_File {
public static void main (String [] args) throws IOException{
int n=5;
int[][]arr=new int[n][n];
int[][]arr2=new int[n][n];
Random random=new Random();
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
arr[i][j]=random.nextInt(100);
}
}
File file=new File("Exercise12_15.txt");
FileWriter out=new FileWriter(file);
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
out.write(arr[i][j]+"\t");
}
out.write("\r\n");
}
out.close();
BufferedReader in=new BufferedReader(new FileReader(file));
String line;
int row=0;
while((line=in.readLine())!=null) {
String[]temp=line.split("\t");
for(int j=0;j<temp.length;j++) {
arr2[row][j]=Integer.parseInt(temp[j]);
}
row++;
}
in.close();
int k=0;
int []arr3=new int[25];
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
arr3[k]=arr2[i][j];
k++;
}
}
Arrays.sort(arr3);
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(arr2[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<arr3.length;i++) {
if(i%5==0)
System.out.println();
System.out.print(arr3[i]+"\t");
}
}
}
仅仅给出实用初稿,题目要求日后完善
效果: