Requirement: There is a string in the known S.txt file: "HCEXFGIJKAMDNOQRZSTUVWYBPL"
Please write the program to read the data content, sorting the data after writing to Ss.txt.
Analysis:
A: Reading data from a file
B: The data exists in a string
C: Convert a string to a string array
D: Sorting a string array
E: Array converted to string
F: Write the string to the file
1 Public Static voidMain (string[] args)throwsIOException {2 //read the data buffer character input stream in a file3BufferedReader br =NewBufferedReader (NewFileReader ("S.txt"));4 //put the data in a string5String s =br.readline ();6 br.close ();7 //Convert a string to a string array8 Char[] ch =S.tochararray ();9 //to sort a string arrayTen arrays.sort (CH); One //array into string AString result =NewString (CH); - - //writes a string to the file buffer character output stream theBufferedWriter BW =NewBufferedWriter (NewFileWriter ("Ss.txt")); - bw.write (result); - bw.close (); - +}
Io Stream Practice 5--reading a string in a file, sorting after it is written to another file