public static void ReadFile() {
String str = null;
try {
FileReader fr = new FileReader("D:\\a.txt");
char[] buf = new char[1024];
int num = 0;
while ((num = fr.read(buf)) != -1) {
str = new String(buf, 0, num);
System.out.println("文件内容是:" + str);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] bu = str.getBytes();
for (int i = 0; i < bu.length; i++) {
int index = locateNextMaxNumber(bu, i);
exchange(bu, i, index);//调用排序
}
System.out.print(new String(bu));
}
public static int locateNextMaxNumber(byte[] a, int sta) {
int staNum = a[sta], staIndex = sta;
for (int i = sta + 1; i < a.length; i++) {
if (a < staNum) {
staIndex = i;
staNum = a;
}
}
return staIndex;
}
public static void exchange(byte[] a, int i, int j) {
byte temp = a;
a = a[j];
a[j] = temp;
}