import java.io.*;
import java.util.Arrays;
public class Sort {
public void TestSort() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("F:\\Java\\IO Study 03\\test.txt"));
int c = 0;
String len;
String[] str = new String[1];
while ((len = br.readLine()) != null) {
str[c] = len;
str = Arrays.copyOf(str, str.length + 1);
c++;
}
if (c != 0) {
int[] ic = new int[c];
c--;
for (int m = 0; m <= c; m++) {
ic[m] = Integer.parseInt(str[m]);
}
for (int i = 1; i < ic.length; i++) {
int x = ic[i];
int j = i - 1;
while (j >= 0 && ic[j] < x) {
ic[j + 1] = ic[j];
j--;
}
ic[j + 1] = x;
}
for (int m = 0; m < ic.length; m++) {
str[m] = String.valueOf(ic[m]);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter("F:\\Java\\IO Study 03\\test.txt"));
for (int m = 0; m < ic.length; m++) {
bw.write(str[m]+"\n");
bw.flush();
}
bw.close();
}else{
System.out.println(" ");
System.exit(-1);
}
}
}
运行前文件中的内容运行后文件中的内容