file与 byte[] 互转
byte 转file
String filepath="D:\\"+getName();
File file=new File(filepath);
if(file.exists()){
file.delete();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(data,0,data,.length);
fos.flush();
fos.close();
file转 byte
FileInputStream inputStream = new FileInputStream(file);
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = inputStream.read()) != -1) {
bytestream.write(ch);
}
byte[] data= bytestream.toByteArray();
bytestream.close();
inputStream.close();
return data;
file与 byte[] 互转的更多相关文章
- 字符串string和内存流MemoryStream及比特数组byte[]互转
原文:字符串string和内存流MemoryStream及比特数组byte[]互转 字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...
- File to byte[] in Java
File to byte[] in Java - Stack Overflow https://stackoverflow.com/questions/858980/file-to-byte-in-j ...
- Go语言网络通信---string与int互转,int64与[]byte互转,int直接互转,string与[]byte互转
string与int互转 #string到int int,err:=strconv.Atoi(string) #string到int64 int64, err := strconv.ParseInt( ...
- byte数组和File,InputStream互转
1.将File.FileInputStream 转换为byte数组: File file = new File("file.txt"); InputStream input = n ...
- JAVA File转Byte[]
/** * 获得指定文件的byte数组 */ public static byte[] getBytes(String filePath){ byte[] buffer = null; try { F ...
- File和byte[]转换
http://blog.csdn.net/commonslok/article/details/9493531 public static byte[] File2byte(String filePa ...
- inputStream、File、Byte、String等等之间的相互转换
一:inputStream转换 1.inputStream转为byte //方法一 org.apache.commons.io.IOUtils包下的实现(建议) IOUtils.toByteArray ...
- 转转转--Java File和byte数据之间的转换
package cn.iworker.file; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; ...
- java File和Byte[]数组 相互转换
public class Test { public static void main(String[] args){ String filePath = "E:\\softoon\\wor ...
随机推荐
- 10 ways to be a faster code reviewer--reference
reference:http://blog.codacy.com/top-10-faster-code-reviews/ This is a blog post of our Code Reading ...
- LeetCode1 Two Sum
题目 :Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- [Adruino]XBEE 无线数据传输实际操作
双轮小车制作实例代码 引用:http://hi.baidu.com/dlfla84/item/52b89017a6209c5cf1090e9b 双轮小车制作 2009-6-12 初步完成了串口数据缓存 ...
- Java基础知识强化之IO流笔记77:NIO之 Selector
Selector(选择器)是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样,一个单独的线程可以管理多个channel,从而管理多个网络连接. 1. ...
- Java基础知识强化之IO流笔记72:NIO之 NIO核心组件(NIO使用代码示例)
1.Java NIO 由以下几个核心部分组成: Channels(通道) Buffers(缓冲区) Selectors(选择器) 虽然Java NIO 中除此之外还有很多类和组件,Channel,Bu ...
- jquery.blockUI.2.31.js 弹出层项目介绍
{insert_scripts files='user.js'} <style type="text/css"> #float_login{border:1px sol ...
- uboot在s3c2440上的移植(1)
一.移植环境 主 机:VMWare--Fedora 9 开发板:Mini2440--64MB Nand,Kernel:2.6.30.4 编译器:arm-linux-gcc-4.3.2.tgz u-b ...
- codeforces 680C C. Bear and Prime 100(数论)
题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #198 (Div. 1) B,C 动态规划
比赛时,开了大号去做,算了半天发现不会做A,囧.于是跑去看B,发现很水?于是很快敲完了,但是A不会,没敢交.于是去看C,一直找规律啊,后来总算调了出来,看了一下榜,发现还是算了吧,直接去睡觉了.第二天 ...
- Convolution and Deconvolution
1.Introduction 2.Convolution 3.Deconvolution 4.Summary