java处理txt文件,并生成文件
2017-01-19 09:52
489 查看
@Test public void transfer() throws IOException{ String tx = null; FileInputStream fis = new FileInputStream("DDDSA2005.TXT"); FileOutputStream fos = new FileOutputStream("newDDDSA2005.CSV"); InputStreamReader read = new InputStreamReader(fis, "UTF-8"); BufferedReader br = new BufferedReader(read); String line = System.getProperty("line.separator"); while ((tx = br.readLine()) != null) { String newtx = tx.substring(0, 19) + "|" + tx.substring(21, 29) + "|" + tx.substring(31, 39) + "|" + tx.substring(39, 43) + "|" + tx.substring(43, 57) + "|" + tx.substring(58, 71) + "|" + tx.substring(71, 76) + "|" + tx.substring(76, 77) + "|" + tx.substring(77, 78) + "|" + tx.substring(78, 79) + "|" + tx.substring(79, 80) + "|" + tx.substring(82, 97) + "|" + tx.substring(99, 114) + "|" + tx.substring(115, 124) + "|" + tx.substring(126, 132) + "|" + tx.substring(132, 138) + "|" + tx.substring(138, 144) + "|" + tx.substring(144, 154) + "|" + tx.substring(154, 164) + "|" + tx.substring(166, 172) + "|" + tx.substring(172, 173); fos.write(newtx.getBytes()); fos.write(line.getBytes()); }
实现按行处理,每行内容按格式加|分隔符。
相关文章推荐
- java 利用输入输出流处理txt文件,并生成新txt文件
- Java 读取本地 UTF8 txt文件乱码处理
- JAVA程序输出到.txt文件的换行符处理
- java生成unicode编码格式的txt文件
- POI以SAX方式解析Excel2007大文件(包含空单元格的处理) Java生成CSV文件实例详解
- 批处理导出项目中所有java文件到txt中
- 《java----实现汉字转换为对应的Unicode码》---批量处理,将要处理的汉字放在chines.txt文件中
- WAS生成的文件:javacore.***.txt 、heapdump.***.phd、core.***.dmp、Snap.***.trc
- JAVA生成TXT日志文件
- Java连接数据库+连续读取文件夹下txt文件+读取出txt文件后字符串简单分割连接处理+导入jar包
- java直接生成zip压缩文件精简代码(跳过txt文件)
- JAVA处理Excel文件---生成简单的Excel文件
- JAVA处理Excel文件---生成简单的Excel文件
- JAVA中使用freemark生成自定义文件(json、excel、yaml、txt)
- Java处理txt文件遇到的问题 (unicode编码)
- 【java】【乱码】Java 读取本地 UTF8 txt文件乱码处理
- java生成文件时使用十六进制0x03作为分隔符处理方法?
- java中生成txt文件,如果已存在就覆盖原文件
- java从数据库导数据生成txt文件的中文编码问题
- 内存溢出WAS生成的文件javacore.***.txt 、heapdump.***.phd、core.***.dmp、Snap.***.trc说明