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 ...
随机推荐
- php与mysql通讯那点事
php与mysql通讯那点事 http://www.cnxct.com/libmysql-mysqlnd-which-is-best-and-what-about-mysqli-pdomysql-my ...
- Tomcat7启动报Error listenerStart错误--转载
原文地址:http://www.cnblogs.com/nayitian/p/3439336.html 问题 Tomcat7在启动时报错,详细信息如下: 十一月 23, 2013 7:21:58 下午 ...
- J2EE常用包:
J2EE常用包: java web开发必掌握的javax.servlet : servlet包及支持javax.servlet.http : http请求支持javax.servlet.jsp : 及 ...
- LeetCode33 Search in Rotated Sorted Array
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- C# mvc--EF中查询的本质
UI层我直接用了窗体程序. 好了 不罗嗦 直接上代码…… private void button1_Click(object sender, EventArgs e) { //1.0创建EF上下文容器 ...
- Android进阶笔记17:3种JSON解析工具(org.json、fastjson、gson)
一. 目前解析json有三种工具:org.json(Java常用的解析),fastjson(阿里巴巴工程师开发的),Gson(Google官网出的),其中解析速度最快的是Gson. 3种json工具下 ...
- Android 4.4 新特性分析-15项大改进!
Google发布了Android 4.4 KitKat,并其同时面世的还有新旗舰Nexus 5.Android 4.4 KitKat有怎样的改进.是否值得升级呢,下面就为大家呈现Android 4.4 ...
- Android Activity的启动过程
文章编辑的太长了,请移步我的csdn博客:http://blog.csdn.net/xyh269 Android Activity的启动过程原文链接:http://blog.csdn.net/xyh2 ...
- Unix系统安装MySQL-python出现UnicodeDecodeError错误解决方法
今天装MySQL-python时候出现了这个错误: error: command ---------------------------------------- Cleaning up... Com ...
- web前端开发(1)
web标准 结构标准.样式标准.行为标准分离 结构标准:xml xhtml html 样式标准:css 行为标准:DOM ECMAScript 符合标准的网页:1.标签小写 2.属性加引号 3. ...