Java文件内容读写
2024-09-03 04:02:07
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");
}
}
最新文章
- 反射实现 AOP 动态代理模式(Spring AOP 的实现 原理)
- js模仿新浪微博限制字数输入
- VM配置一个待安装LUNIX系统的环境
- linux 系统下开机自动启动oracle 监听和实例 (亲测有效)
- hibernate将本地SQL查询结果封装成对象
- Linux复制指定目录下的文件夹结构
- 《Spark大数据处理:技术、应用与性能优化 》
- [LeetCode#204]Factorial Trailing Zeroes
- UVA 10129-Play on Words(欧拉通路)
- Android Activity 启动模式详解
- Android应用开发学习笔记之绘图
- Nginx运行Laravel的配置
- 2015十大顶级开源ERP系统点评
- 【Ubuntu 16】安装deb
- html select 标签设置默认选中
- Window环境下搭建Git服务器
- 学会学习:高效学习方式(使用vscode-snippet有感)
- Django之Form、ModelForm 组件
- MySQL.ERROR 1133 (42000): Can't find any matching row in the user table
- ylz简单增删改查实现
热门文章
- Android模板制作
- 在colab上运行style-transfer
- sql通过 openrowset查询csv文件
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'needDao' defined in URL
- 解决python pip安装提示";not a supported wheel on this platform";
- SAP成都研究院安德鲁:自己动手开发一个Chrome Extension
- (转)使用Spring配置文件实现事务管理
- (转)编码剖析Spring依赖注入的原理
- VINS-Fusion代码阅读(四)
- tree 树状构建