爱嘉牛LA

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
package regionForKeywords;


import java.io.*;

/**
 * Created by huangjiahong on 2016/2/25.
 */
public class RegionKeywordExcelTransform {

    public static void main(String[] args) {

        String inputFileName="D:\\USER\\huangjiahong\\Desktop\\region.txt";
        String outputFileName="D:\\USER\\huangjiahong\\Desktop\\regionKeywords.txt";
        File file = new File(inputFileName);
        String line=null;
        int errline=0;
        int regionN=0;

        try {
            BufferedReader reader =new BufferedReader(new FileReader(file));
            File outFile = new File(outputFileName);
            FileWriter write = new FileWriter(outputFileName, false);

            if(!outFile.exists()){
                outFile.createNewFile();
            }
            while (null != (line = reader.readLine())){
                try {
                    String[] lineSplit=line.split("\t");
                    String regionName=lineSplit[0];
                    regionN++;
                    String keywords[]=lineSplit[1].split("\\|");
                    //专区名也索引进去
//                    if(regionN==1||regionN==15) {
                        write.write(regionName + "\t" + regionN + "\t" + regionName + "\n");

                        for (String kw : keywords) {
                            write.write(kw + "\t" + regionN + "\t" + regionName + "\n");
                        }
//                    }
                }catch (ArrayIndexOutOfBoundsException a){
                    System.out.println((errline++)+":"+line);
                    a.printStackTrace();
                }

            }
            reader.close();
            write.close();

        } catch (IOException e) {
            e.printStackTrace();

        }
        System.out.println("finished");
    }
}

 

posted on 2016-02-26 09:52  爱嘉牛LA  阅读(218)  评论(0编辑  收藏  举报