package com.edong.stream.example;
import java.io.*;
import java.util.Properties;
/**
* @author 张 柏
* @copyright qwnbc 2009-5-27
* 有一个input.txt文件
* 该文件每一行有五个数字
* 1,1,2,4,2
* 1,1,2,2,4
* 1,3,73,189,8
* 2,4,3,55,9
* 1,4,12,34,67
* 1,5,8,9,13
* 3,5,8,78,55
* 对这个文件进行排序
* 输出形式是output.txt
* 1,1,2,2,4
* 1,1,2,2,4
* 1,1,8,73,189
* 1,4,12,34,67
* 1,5,8,9,13
* 2,3,4,9,55
* 3,5,8,55,78
*/
public class Fantasy {
public static void main(String args[]) throws IOException {
FileReader fr = new FileReader("c:\\input.txt");
BufferedReader re = new BufferedReader(fr);
FileWriter fw=new FileWriter("c:\\output.txt");
BufferedWriter bw=new BufferedWriter(fw);
while (1 == 1) {
if (re.ready()) {
String str = re.readLine();
String[] arrInt = str.split(",");
for (int i = 0; i < arrInt.length; i++) {
String temp = null;
for (int j = 0; j < arrInt.length - i - 1; j++) {
String s1 = arrInt[j].trim();
String s2 = arrInt[j + 1].trim();
if (s1.hashCode() > s2.hashCode()) {
temp = arrInt[j];
arrInt[j] = arrInt[j + 1];
arrInt[j + 1] = temp;
}
}
}
StringBuffer sb=new StringBuffer();
for (int k = 0; k < arrInt.length; k++) {
if (k < arrInt.length - 1) {
sb.append(arrInt[k] + ",");
} else
sb.append(arrInt[k]);
}
Properties pp = System.getProperties();
String newLine = pp.getProperty("line.separator");
bw.write(sb.toString()+newLine);
} else
break;
}
fr.close();
bw.close();
}
}
import java.io.*;
import java.util.Properties;
/**
* @author 张 柏
* @copyright qwnbc 2009-5-27
* 有一个input.txt文件
* 该文件每一行有五个数字
* 1,1,2,4,2
* 1,1,2,2,4
* 1,3,73,189,8
* 2,4,3,55,9
* 1,4,12,34,67
* 1,5,8,9,13
* 3,5,8,78,55
* 对这个文件进行排序
* 输出形式是output.txt
* 1,1,2,2,4
* 1,1,2,2,4
* 1,1,8,73,189
* 1,4,12,34,67
* 1,5,8,9,13
* 2,3,4,9,55
* 3,5,8,55,78
*/
public class Fantasy {
public static void main(String args[]) throws IOException {
FileReader fr = new FileReader("c:\\input.txt");
BufferedReader re = new BufferedReader(fr);
FileWriter fw=new FileWriter("c:\\output.txt");
BufferedWriter bw=new BufferedWriter(fw);
while (1 == 1) {
if (re.ready()) {
String str = re.readLine();
String[] arrInt = str.split(",");
for (int i = 0; i < arrInt.length; i++) {
String temp = null;
for (int j = 0; j < arrInt.length - i - 1; j++) {
String s1 = arrInt[j].trim();
String s2 = arrInt[j + 1].trim();
if (s1.hashCode() > s2.hashCode()) {
temp = arrInt[j];
arrInt[j] = arrInt[j + 1];
arrInt[j + 1] = temp;
}
}
}
StringBuffer sb=new StringBuffer();
for (int k = 0; k < arrInt.length; k++) {
if (k < arrInt.length - 1) {
sb.append(arrInt[k] + ",");
} else
sb.append(arrInt[k]);
}
Properties pp = System.getProperties();
String newLine = pp.getProperty("line.separator");
bw.write(sb.toString()+newLine);
} else
break;
}
fr.close();
bw.close();
}
}