日期:2014-05-20 浏览次数:20926 次
public static void main(String[] args) {
FileReader fr = null;
FileWriter fw = null;
try {
fr = new FileReader("d:/a.txt");
fw = new FileWriter("d:/b.txt");
char[] buf = new char[1024];
int len = 0;
while ((len = fr.read(buf)) != -1) {
//由于楼主给的字符有限
//所以循环一次就可以了,直接就在这里排序了
StringBuffer sb = new StringBuffer();
for(int i=0;i<len;i++){
sb.append(buf[i]);
}
String b =sb.toString();
System.out.println(b.toString());
// String b="wnadsmdjsa";
char[] c=b.toCharArray();
Arrays.sort(c);
fw.write(c,0,len);
}
} catch (IOException e) {
System.out.println(e.toString());
} finally {
try {
if (fw != null)
fw.close();
} catch (IOException e) {
System.out.println(e.toString());
}
try {
if (fr != null)
fr.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
String b="wnadsmdjsa";
char[] c=b.toCharArray();
Arrays.sort(c);
System.out.println(c);