Ejemplo n.º 1
0
  /** 提取Tag */
  public void extractTags(List<NewsItem> itemList, String fileName) throws IOException {

    File tagFile = new File(fileName);
    if (tagFile.exists()) {
      System.out.println("文件存在");
    } else {
      System.out.println("文件不存在,正在创建...");
      if (tagFile.createNewFile()) {
        System.out.println("文件创建成功!");
      } else {
        System.out.println("文件创建失败!");
      }
    }
    BufferedWriter output = new BufferedWriter(new FileWriter(tagFile, true));

    for (int i = 0; i < itemList.size(); i++) {
      NewsItem newsItem = itemList.get(i);
      logger.info(newsItem.getTitle());
      List<Tag> tags = newsItem.getTagList();
      for (int j = 0; j < tags.size(); j++) {
        output.append(tags.get(j).getTag() + "@@tag" + System.getProperty("line.separator"));
      }
    }
    output.close();
  }
Ejemplo n.º 2
0
  public void extractContents(List<NewsItem> itemList, String filePath) throws IOException {

    for (int i = 0; i < itemList.size(); i++) {

      File contentFile = new File(filePath + i + ".txt");
      if (contentFile.exists()) {
        System.out.println("文件存在");
      } else {
        System.out.println("文件不存在,正在创建...");
        if (contentFile.createNewFile()) {
          System.out.println("文件创建成功!");
        } else {
          System.out.println("文件创建失败!");
        }
      }
      BufferedWriter output = new BufferedWriter(new FileWriter(contentFile, true));

      NewsItem newsItem = itemList.get(i);
      //			logger.info(newsItem.getSummary());
      output.append(newsItem.getSummary());
      output.close();
    }
  }