将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 ...
随机推荐
- JS export 异步导出
function getUrl () { req().then(res => { console.log(res); }).catch(err => { console.log(err); ...
- phpstudy如何配置域名
其他选项菜单=>站点域名管理=>站点管理填入信息后点击“新增”按钮=>点击“保存设置并生成配置文件”按钮=>打开hosts=>127.0.0.1 www.gohosts. ...
- python 杂记 网络
参考资料:https://www.cnblogs.com/gareth-yu/p/9097943.htmlimport selectors import socket sel = selectors. ...
- [hdoj4578][多延迟标记的线段树]
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)T ...
- [2019HDU多校第五场][HDU 6626][C. geometric problem]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6626 题目大意:给出平面上六个点\(A,B,M,N,X,Y\)以及两条直线\(L1,L2\),要求在四 ...
- 12、Spring Boot 2.x 集成 MongoDB
1.12 Spring Boot 2.x 集成 MongoDB 完整源码: Spring-Boot-Demos
- php注意事项|要点
1. 用单引号代替双引号来包含字符串,这样做会更快一些.因为 PHP 会在双引号包围的 字符串中搜寻变量,单引号则不会,注意:只有 echo 能这么做,它是一种可以把多个字符 串当作参数的“函数”(译 ...
- poi操作excel之: 将NUMERIC转换成TEXT
一.NUMERIC TO TEXT(生成excel)代码生成一个excel文件: public static void generateExcel() throws Exception { XSSFW ...
- 【原创】FltGetFileNameInformation蓝屏分析
FAULTING_IP: nt!SeCreateAccessStateEx+5b80564184 848788000000 test byte ptr [edi+88h],al TRAP_FRAME: ...
- spring cloud学习
https://gitee.com/ylimhhmily/SpringCloudTutorial/tree/master hystrix配置不生效问题https://blog.csdn.net/lvy ...