public static void main(String[] args) throws IOException {
    Reader r = new Reader();
    ArrayList<String> labels = r.read("test.label");
    ArrayList<String> data = r.read("test.data");

    FileWriter fw = new FileWriter("test20.txt");
    for (int i = 1; i <= labels.size(); i++) {
      int label = Integer.parseInt(labels.get(i - 1));
      String doc = "" + (label - 1);
      while (!data.isEmpty()) {
        String s = data.get(0);
        String[] temp = s.split(" ");
        if (Integer.parseInt(temp[0]) != i) {
          break;
        }
        data.remove(0);
        String oneWord = " " + temp[1] + ":" + temp[2];
        doc = doc + oneWord;
      }
      doc = doc + "\r\n";
      fw.write(doc);
      System.out.println("doc " + i + "  finished");
    }
    fw.close();
  }
  public ArrayList<OneDoc> readText(String fileName) {

    ArrayList<OneDoc> result = new ArrayList<OneDoc>();

    Reader r = new Reader();
    ArrayList<String> stringList = r.read(fileName);
    for (String s : stringList) {
      result.add(new OneDoc(s));
    }

    return result;
  }