java txt
来源:互联网 发布:safari windows 下载 编辑:程序博客网 时间:2024/04/29 16:45
package cn.com.glxt.fifle;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
import org.apache.log4j.Logger;
import cn.com.glxt.common.FileUtil;
public class CreateTxt {
private static final Logger LOG = Logger.getLogger(CreateTxt.class);
public static void main(String[] args) {
String directory = "D:/Users/test/txt";
String pathname = directory+File.separator+UUID.randomUUID()+".dat";
FileUtil.mkDir(directory);
File txtFile = FileUtil.mkFile(pathname);
writeTxt(txtFile, 2,true);
}
private static void writeTxt(File file,int rows,boolean isAppend){
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file,isAppend);
StringBuffer sbf = new StringBuffer();
for(int i=0;i<rows;i++){
sbf.append(getContent()).append("\r\n");
if(rows%500 ==0){
fos.write(sbf.toString().getBytes("UTF-8"));
sbf.delete(0, sbf.length());
}
}
if(sbf.length() >0){
fos.write(sbf.toString().getBytes("UTF-8"));
}
} catch (FileNotFoundException e) {
LOG.error("找不到文件"+e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
LOG.error("字节码转换错误"+e.getMessage(), e);
} catch (IOException e) {
LOG.error("IO错误"+e.getMessage(), e);
}finally{
if(fos != null){
try {
fos.close();
} catch (IOException e) {
LOG.error("IO错误"+e.getMessage(), e);
}
}
}
}
/**
* 模拟业务数据
* @return
*/
private static String getContent(){
return "10001|20150623|400.25|张三|RMB";
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
import org.apache.log4j.Logger;
import cn.com.glxt.common.FileUtil;
public class CreateTxt {
private static final Logger LOG = Logger.getLogger(CreateTxt.class);
public static void main(String[] args) {
String directory = "D:/Users/test/txt";
String pathname = directory+File.separator+UUID.randomUUID()+".dat";
FileUtil.mkDir(directory);
File txtFile = FileUtil.mkFile(pathname);
writeTxt(txtFile, 2,true);
}
private static void writeTxt(File file,int rows,boolean isAppend){
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file,isAppend);
StringBuffer sbf = new StringBuffer();
for(int i=0;i<rows;i++){
sbf.append(getContent()).append("\r\n");
if(rows%500 ==0){
fos.write(sbf.toString().getBytes("UTF-8"));
sbf.delete(0, sbf.length());
}
}
if(sbf.length() >0){
fos.write(sbf.toString().getBytes("UTF-8"));
}
} catch (FileNotFoundException e) {
LOG.error("找不到文件"+e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
LOG.error("字节码转换错误"+e.getMessage(), e);
} catch (IOException e) {
LOG.error("IO错误"+e.getMessage(), e);
}finally{
if(fos != null){
try {
fos.close();
} catch (IOException e) {
LOG.error("IO错误"+e.getMessage(), e);
}
}
}
}
/**
* 模拟业务数据
* @return
*/
private static String getContent(){
return "10001|20150623|400.25|张三|RMB";
}
}
阅读全文
0 0
- java txt
- JAVA读取TXT文件 写入TXT文件
- java操纵TXT
- 将JAVA写入TXT
- java 读写txt文本文件
- Java分割txt文件
- java读取txt文本
- Java读写txt文件
- JAVA读取txt文件
- java解析txt文件
- java 导出 txt
- java读写txt文件
- java读取txt
- java 写txt文件
- Java操作txt文件
- java 选择题目.txt
- java txt 编码格式
- java操作txt文件
- 剑指offer之四---用两个栈实现队列
- JavaScript-2-3:offset、event
- Spring 的配置文件简化与注解的使用
- visual studio 2015安装破解visual assist
- 创建Spark Applition
- java txt
- ZooKeeper实现分布式队列Queue
- 1.Android开发环境搭建
- Atitit.印章文化 印章的起源历史与发展 v2 r99 .docx
- C++中运算符的重载
- ubuntu16.04 最新vsftpd搭建完整教程(原创2017.09.18)
- Hibernate基础
- <开发日记1> 准备
- window.location.href