• Java文件内容读写


    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("	");
                        String regionName=lineSplit[0];
                        regionN++;
                        String keywords[]=lineSplit[1].split("\|");
                        //专区名也索引进去
    //                    if(regionN==1||regionN==15) {
                            write.write(regionName + "	" + regionN + "	" + regionName + "
    ");
    
                            for (String kw : keywords) {
                                write.write(kw + "	" + regionN + "	" + regionName + "
    ");
                            }
    //                    }
                    }catch (ArrayIndexOutOfBoundsException a){
                        System.out.println((errline++)+":"+line);
                        a.printStackTrace();
                    }
    
                }
                reader.close();
                write.close();
    
            } catch (IOException e) {
                e.printStackTrace();
    
            }
            System.out.println("finished");
        }
    }
  • 相关阅读:
    字符编码
    IO流技术
    TreeMap使用和Comparable比较
    Collections工具类
    使用迭代器进行遍历时
    238. 除自身以外数组的乘积
    python 字典按键、值排序
    collections.Counter用法
    442. 数组中重复的数据
    1395. 统计作战单位数
  • 原文地址:https://www.cnblogs.com/aijianiula/p/5219356.html
Copyright © 2020-2023  润新知