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"); } }