Java NIO 写文件
来源:互联网 发布:linux中echo 编辑:程序博客网 时间:2024/05/16 08:40
//将邮箱 姓名和最后生成的链接数据写入csv文件
private void writeCsv(String content, String fileName) throws IOException {
File f = new File(defaultCsvpath);
f.setWritable(true);
if (!f.exists()) { //如果该路径不存在,就创建该路径
f.mkdir();
}
String filePath = defaultCsvpath + "/" + fileName; //得到完整文件路径
FileOutputStream fos = null;
FileChannel fc_out = null;
try {
fos = new FileOutputStream(filePath, true);
fc_out = fos.getChannel();
ByteBuffer buf = ByteBuffer.wrap(content.getBytes());
buf.put(content.getBytes());
buf.flip();
fc_out.write(buf);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != fc_out) {
fc_out.close();
}
if (null != fos) {
fos.close();
}
}
}
private void writeCsv(String content, String fileName) throws IOException {
File f = new File(defaultCsvpath);
f.setWritable(true);
if (!f.exists()) { //如果该路径不存在,就创建该路径
f.mkdir();
}
String filePath = defaultCsvpath + "/" + fileName; //得到完整文件路径
FileOutputStream fos = null;
FileChannel fc_out = null;
try {
fos = new FileOutputStream(filePath, true);
fc_out = fos.getChannel();
ByteBuffer buf = ByteBuffer.wrap(content.getBytes());
buf.put(content.getBytes());
buf.flip();
fc_out.write(buf);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != fc_out) {
fc_out.close();
}
if (null != fos) {
fos.close();
}
}
}
- Java NIO 写文件
- Java NIO读,写,拷贝文件
- java nio 常见的nio类, nio 写文件方法, nio 比io 的优势
- Java NIO逐行读文件并写文件
- java NIO实现的文件复制(包括文件与文件夹复制) NIO读取数据与写数据
- java nio 文件锁小例
- java nio 文件锁小例
- JAVA NIO 文件保存
- Java nio 传输文件
- java文件io、nio
- Java NIO 读写文件
- java NIO 传送文件
- Java NIO传输文件
- java NIO复制文件
- java NIO读写文件
- Java NIO-文件锁
- java.nio 映射文件
- Java NIO 文件锁
- LaTeX使用--使用XeLaTeX支持中文(可以放弃Office了)
- FlexClient, MessageClient, and FlexSession
- 基于用户组织角色权限和资源的五要素
- 访问android平台的通话记录CallLog
- VMware虚拟机不能发声
- Java NIO 写文件
- 04_IHE简介
- sohu单点登录
- Log4j的html输出格式:HTMLLayout 类重写,根据自身需要输出不同列
- C语言关键字学习(1)----- extern
- 实例讲解1--模式匹配
- Js_异常处理
- android中的内存泄露问题,感觉挺重要的
- 三句话影响人的一生