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 ...
随机推荐
- Topology: The Architecture of Distributed Systems--reference
reference:http://blog.couchbase.com/topology-architecture-distributed-systems You can’t judge a book ...
- ubuntu 上使用apt-get安装oracle-jdk
Installing default JRE/JDK sudo apt-get updatesudo apt-get install default-jresudo apt-get install d ...
- ubuntu16.04 编译安装mysql5.7.x,以及配置使用
編譯與安裝: 源码下载地址:http://dev.mysql.com/downloads/mysql/ 选择Generic Linux (Architecture Independent), C ...
- centos下cp -r 命令可拷贝文件夹
LINUX命令的cp -r 和-R的区别 功能上是等价的.不加-r或者-R的时候,只拷贝文件,不拷贝文件夹:加上后则会拷贝文件夹——包括下一级的子文件夹,以及子文件夹中的子文件夹,余此类推.rm的-R ...
- BZOJ 2819: Nim dfs序维护树状数组,倍增
1.随机选两个堆v,u,询问若在v到u间的路径上的石子堆中玩Nim游戏,是否有必胜策略,如果有,vfleaking将会考虑将这些石子堆作为初始局面之一,用来坑玩家.2.把堆v中的石子数变为k. 分析: ...
- linux中crontab和at
1. Red Hat的发行版本中,通常还可以使用工具ntsysv设置服务的自启动状态. #类似chkonfig 服务名 on|off 2.系统服务脚本目录:/etc/init.d 3.ps: -a:显 ...
- [Excel操作]Microsoft Office Excel 不能访问文件
最近,客户服务器迁移,因操作系统环境变化而引起的的环境问题一堆,遇到的问题并解决方法在“[Excel]操作”类别会体现. Microsoft Office Excel 不能访问文件“C:\\LMSEx ...
- android菜鸟学习笔记2----关于adb
adb : android debug bridge android调试桥 路径:adt-bundle目录/sdk/platform-tools/adb.exe 常见的adb命令: adb devic ...
- 干货:Android 源码使用心得分享
我相信很多初学者会和我一样经常在网上去找Android开发源码,但是往往因为运行不起来非常的懊恼!在做爱开发网站的时候,收集App代码时就遇到了这种困难,我相信网络上面的源码大部分在发布前 ...
- SQL Server 2008 报表服务入门
目录 报表服务的安装与配置 开发报表的过程 报表制作实例 一.报表服务的安装与配置 1. 报表服务的组件 2. 报表服务 2008 的安装 2.1在SQL Server 2008上安装报表服务有两种方 ...