package com.itheima.charstream1;
import java.io.*;
import java.util.Arrays;
public class CharStreamDemo14 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(".\\sort.txt"));
String line = br.readLine();
System.out.println("读取到的数据:"+line);
String[] split = line.split(" ");
int[] arr=new int[split.length];
for (int i = 0; i < split.length; i++) {
String s = split[i];
int number = Integer.parseInt(s);
arr[i]=number;
}
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
br.close();
BufferedWriter bw=new BufferedWriter(new FileWriter(".\\sort.txt"));
for (int i = 0; i < arr.length; i++) {
bw.write(arr[i]+" ");
bw.flush();
}
bw.close();
}
}
|