今天爱分享给大家带来有一个数据文件:123 34 17 651234 345….这些数据都是随机产生的,编写程序读出该文件.并将其以从大到小的顺序输出到另一个文件中.【面试题详解】,希望能够帮助到大家。
public void readtext(){ File file = new File("D:\test.txt"); List list= new ArrayList(); try { BufferedReader br=new BufferedReader(new FileReader(file)); String data = ""; String line = null; while ( (line = br.readLine()) != null) { data = data.concat(line); } StringTokenizer stoken = new StringTokenizer(data, " "); while (stoken.hasMoreTokens()) { int i = Integer.parseInt(stoken.nextToken()); list.add(i); } } catch(Exception ex) {} String[] str = new String[list.size()]; for(int i=0;i=i;j--) { if(str[j]>str[j-1]) { iTemp = str[j-1]; str[j-1] = str[j]; str[j] = iTemp; } } String result = ""; for(int i=0;i