将ByteBuffer保存成文件
String dest = "d:/download/" + name; Path path = Paths.get(dest).getParent().toAbsolutePath().normalize(); if(!Files.exists(path))
{
try {
Files.createDirectories(path);
} catch (IOException e) {
e.printStackTrace();
}
} try (FileChannel fc = new FileOutputStream(dest).getChannel()){ ByteBuffer buffer = getResponseAttachment(url);
fc.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
import java.io.File;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; public class Main {
public static void main(String[] argv) throws Exception {
ByteBuffer bbuf = ByteBuffer.allocate(100);
File file = new File("filename"); boolean append = false; FileChannel wChannel = new FileOutputStream(file, append).getChannel(); wChannel.write(bbuf); wChannel.close();
}
}
String dest = "d:/download/" + name;
try (FileChannel fc = FileChannel.open(Paths.get(dest), StandardOpenOption.WRITE)){
ByteBuffer buffer = getResponseAttachment(url);
fc.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
将ByteBuffer保存成文件的更多相关文章
- Ubuntu10.04中利用V4L2读取摄像头数据并保存成文件【转】
转自:http://blog.chinaunix.net/uid-29339876-id-4042245.html 利用V4L2读取UVC摄像头数据并保存成视频文件,主要参考http://linuxt ...
- 把打印的内容保存成文件(PDF)
有时候网页的内容和打印的内容会有一些差异,需要把打印的内容倒出来.是有办法的. 1.以谷歌为内核的浏览器示例,按Ctrl+p快捷键打开打印对话框,如图: 2.点击更改按钮,更改打印机,会出现选择目标打 ...
- 提取WORD中的所有InlineShape图片并保存成文件
InlineShape表示的类型其实不只是图片,还包括OLE, ACTIVE X等. 下面是MSDN中的定义:Represents an object in the text layer of a d ...
- oracle学习之数据库数据保存成文件
常常需要将数据库中的数据生成文档,由于比较喜欢脚本的方式,所以就需要使用spool的时候进行格式设置,以下简单整理了一下oracle中进行格式设置的一些东西,一共十八条,其实常用的也就那么几个,稍后会 ...
- C# byte[]保存成文件
string path = Server.MapPath(@"\a.pdf"); FileStream fs = new FileStream(path, FileMode.Cre ...
- lumisoft会将eml后缀格式的附件给解析成文本,这里保存成文件
MIME_Entity[] attachments = mime.Attachments; foreach (MIME_Entity entity in attachments) { string f ...
- php把数组保存成文件格式
php把数组保存为文件格式的函数实例,或许有的还没听说过可以把数组保存成文件,其实这样做也是另有它用的,两种方法各有千秋,有兴趣的PHP爱好者敬请参阅: $file="./cache/fil ...
- tcpdump抓包并保存成cap文件
首选介绍一下tcpdump的常用参数 tcpdump采用命令行方式,它的命令格式为: tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ] [ -i 网络接 ...
- 将Chrome调试器里的JavaScript变量保存成本地JSON文件
我写了一个系列的文章,主要用来搜集一些供程序员使用的小工具,小技巧,帮助大家提高工作效率. 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diag ...
随机推荐
- Service Broker 消息队列的方式实现数据同步
SQL Server 2008中SQL应用系列--目录索引 导读:本文主要涉及Service Broker的基本概念及建立一个Service Broker应用程序的基本步骤. 一.前言: Servic ...
- nomn文件分析
#encoding=gbk import os import re import math from os import path ''' 手动输入文件nmon文件路径,要截取的开始时间,结束时间 ' ...
- 如何判断PHP空间是否支持curl、gzip等功能
在网站根目录新建v.php,输入以下代码: <?php $f=@trim($_GET['f']); if(function_exists($f)) echo '支持'.$f; else echo ...
- http协议头
1. ctx->AddResponseHeader("Content-Type", "application/octet-stream"); ctx-&g ...
- 大数据之路week05--day01(I/O流阶段一 之File)
众所周知,我们电脑中有许许多多的文件夹和文件,文件的形式也有许多不同的格式,文件夹中也可以新建文件夹的存在,也就是多层的一步一步的嵌套. 我们想要实现I/O操作,就必须知道硬盘上文件的表现形式. 而J ...
- Spring入门篇——AOP基本概念
1.什么是AOP及实现方式 什么是AOP AOP:Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术 主要 ...
- python_datetime模块和time模块
1.datetime模块 获取当前时间: import datetime # 获取当前时间 ctime = datetime.datetime.now() print(ctime) 只显示:年-月-日 ...
- UEditor设置内容setContent()失效的解决方法
ueditor常见用法: https://blog.csdn.net/qq_31879707/article/details/54894735#UE.Editor:setContent() UEdit ...
- Windows10关闭自动更新总结
试过好多关闭windows自动更新的方法,但是在每次重启后发现C盘又塞了一堆更新包,强迫症的我必须要彻底关闭它! 1. services关闭 运行 services.msc ,找到Windows Up ...
- 函数对话框confirm()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...