Java 阅读TXT文件
public class GenCategoryAttrItemHandler { private final static String INPUT_FILE_PATH = "input/category_attr_item.txt";
private final static String OUTPUT_FLIE_PATH = "output/category_attr_itemList.txt"; /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
GetDataFromFile();
WriteDataToFile();
System.out.println("ok");
} /**
* 从文件提取数据。格式化到程序中
* @throws IOException
*/
public static void GetDataFromFile() throws IOException {
final String DELIMITER = "\t"; BufferedReader br = null;
try {
File file = new File(INPUT_FILE_PATH);
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String line = null;
while (null != (line=br.readLine())) {
String[] strs = line.split(DELIMITER);
Category category = new Category(Long.parseLong(strs[0]),strs[1]);
Attribute attribute = new Attribute(Long.parseLong(strs[2]),strs[3]);
Item item = new Item(Long.parseLong(strs[4]),strs[5]);
...
}// while
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != br) {
br.close();
}
}
} /**
* 将格式化的数据写入文件里
* @throws IOException
*/
public static void WriteDataToFile() throws IOException {
final String DELIMITER = "\t"; BufferedWriter bw = null;
try {
File file = new File(OUTPUT_FLIE_PATH);
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); for (int i=1; i<12; ++i) {
...
bw.write(outValue); // 将数据写入文件里
bw.newLine(); // 新建一个换行符
bw.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != bw) {
bw.close();
}
}
}
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Java 阅读TXT文件的更多相关文章
- Java读写txt文件
1.Java读取txt文件 1.1.使用FileInputStream: public static String readFile(File file, String charset){ //设置默 ...
- Java读取txt文件
package com.loongtao.general.crawler.slave.utils; import java.io.BufferedReader; import java.io.File ...
- java 读取TXT文件的方法
java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...
- java读取TXT文件的方法
java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...
- java读取txt文件内容
package read; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public ...
- java读取txt文件的2中方法---并将内容(每一行以固定的字符分割切成2段)存到map中去
#java读取txt文件的第一种方法 /** * 方法:readTxt * 功能:读取txt文件并把txt文件的内容---每一行作为一个字符串加入到List中去 * 参数:txt文件的地址 * 返回: ...
- Java读取txt文件信息并操作。
一.java读取txt文件内容 import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.Fi ...
- JAVA获取txt文件内容
JAVA 读取txt文件内容 通常,我们可以直接通过文件流来读取txt文件的内容,但有时可能会出现乱码!此时只要设置一下文件字符编码即可. public class txttest { /** * 读 ...
- Java读取txt文件、excel文件的方法
Java读取txt文件.excel文件的方法 1.读取txt文件 public static String getFileContent(String filePath,String charset) ...
随机推荐
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- [Ramda] Rewrite if..else with Ramda ifElse
From: const onSeachClick = (searchTerm) => { if(searchTerm !== '') { searchForMovies(searchTerm) ...
- WPF中自动增加行(动画)的TextBox
原文:WPF中自动增加行(动画)的TextBox WPF中自动增加行(动画)的TextBox WPF中的Textbox控件是可以自动换行的,只要设置TextWrapping属性为"Wrap& ...
- AJAX简介(转)
AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.它使用:使用XHTML+CSS来表示信息: ...
- VB的MSHFlexGrid控件内容导入Excel
机房收费系统中有非常多窗口用到导出到Excel,说一下vb与Excel的交互,怎样才干将MSHFlexgrid中的内容导出到Excel. 首先在VB中加入引用Microsoft Excel 14.0 ...
- BZOJ 1864 三色二叉树 - 树型dp
传送门 题目大意: 给一颗二叉树染色红绿蓝,父亲和儿子颜色必须不同,两个儿子颜色必须不同,问最多和最少能染多少个绿色的. 题目分析: 裸的树型dp:\(dp[u][col][type]\)表示u节点染 ...
- 【BZOJ 1038】[ZJOI2008]瞭望塔
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] [题解] 可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表 ...
- CORDOVA :添加cordova-plugin-file-opener2插件cordova打包报错
原文:CORDOVA :添加cordova-plugin-file-opener2插件cordova打包报错 最近在接触android项目,其中涉及到APP自动更新的问题,当新APP下载成功后需要打开 ...
- How to provide highlighting with Spring data elasticsearch
How to provide highlighting with Spring data elasticsearch @Test public void shouldReturnHighlighted ...
- C# Color结构的各属性颜色对照表(转)
转自:http://blog.sina.com.cn/s/blog_454dc49501016q2p.html Color.AliceBlue 240,248,255 Color.LightSalmo ...