海外社交网站开发,邢台市教育考试院,html如何做购物网站,网页设计技巧需求#xff1a;已知s.txt文件中有这样的一个字符串#xff1a;“hcexfgijkamdnoqrzstuvwybpl” 请编写程序读取数据内容#xff0c;把数据排序后写入ss.txt中。分析#xff1a; A#xff1a;读取文件中的数据 B#xff1a;把数据存在一个字符串中 C… 需求已知s.txt文件中有这样的一个字符串“hcexfgijkamdnoqrzstuvwybpl” 请编写程序读取数据内容把数据排序后写入ss.txt中。分析 A读取文件中的数据 B把数据存在一个字符串中 C把字符串转换成字符串数组 D对字符串数组进行排序 E数组转换成字符串 F把字符串写入文件中 1 public static void main(String[] args) throws IOException {2 // 读取文件中的数据 字符缓冲输入流3 BufferedReader br new BufferedReader(new FileReader(s.txt));4 // 把数据存在一个字符串中5 String s br.readLine();6 br.close();7 // 把字符串转换成字符串数组8 char[] ch s.toCharArray();9 // 对字符串数组进行排序
10 Arrays.sort(ch);
11 //数组转换成字符串
12 String result new String(ch);
13
14 //把字符串写入文件中 字符缓冲输出流
15 BufferedWriter bw new BufferedWriter(new FileWriter(ss.txt));
16 bw.write(result);
17 bw.close();
18
19 } 转载于:https://www.cnblogs.com/LZL-student/p/5927798.html