/*
内容格式如下:第一行表示某个url ,第二行表示上面url被访问的次数。
根据字典顺序对url排序,不能破坏url与访问次数的对应关系
*/
package test;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class order {
public static void main(String[] args) throws IOException {
List list = new ArrayList();
// 读取文件流
FileReader reader = null;
// 读取原ID文件
int count = 0;
try {
reader = new FileReader("/data/idfAnalyse1Whbase");// 读取url文件
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader br = new BufferedReader(reader);
String s1 = null;
String buf1 = null;
String buf2 = null;
while ((s1 = br.readLine()) != null) {
System.out.println("reader cbuffer " + s1);
if (count % 2 == 0) {
// channel
buf1 = s1;
} else {
buf2 = s1;
String[] temp = new String[2];
temp[0] = buf1;
temp[1] = buf2;// 数目
list.add(temp);
}
count++;
}
br.close();
System.out.println("reader closed"+list.size());
reader.close();
for (int i = 0; i
for (int j = i + 1; j
int intTemp = list.get(i)[0].compareToIgnoreCase(list.get(j)[0]);
if (intTemp > 0) {
String strTemp[] = new String[2];
strTemp = list.get(j);
list.set(j, list.get(i));
list.set(i, strTemp);
}
}
}
String resultFileName = "/data/orderidfAnalyse1Whbase";
FileWriter fileWriter = null;
//写入文件流
try
{
fileWriter = new FileWriter(resultFileName, true);
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (int i = 0; i
System.out.println("i is "+i);
fileWriter.write(list.get(i)[0] + "\n" + list.get(i)[1]+"\n");
System.out.println(list.get(i)[0] + "\n" + list.get(i)[1]);
}
System.out.println(list.size());
try
{
fileWriter.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}