/**
* 获得指定文件的byte数组
*/
private byte[] getBytes(String filePath){
byte[] buffer = null;
try {
File file = new File(filePath);
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
byte[] b = new byte[1000];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return buffer;
} /**
* 根据byte数组,生成文件
*/
public static void getFile(byte[] bfile, String filePath,String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File dir = new File(filePath);
if(!dir.exists()&&dir.isDirectory()){//判断文件目录是否存在
dir.mkdirs();
}
file = new File(filePath+"\\"+fileName);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bfile);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}

最新文章

  1. 北京培训记day4
  2. 前端试题本(HTML+CSS篇)
  3. Android APP测试的日志文件抓取
  4. JQuery ajax url传值与data传值的区别
  5. Tomcat上的项目部署到WebLogic上の注意事项
  6. windows phone listbox虚拟化(下)
  7. 《Cortex-M0权威指南》之Cortex-M0编程入门
  8. hibernate配置文件详细解释
  9. Java面试10|数据库相关
  10. Yum -userguide
  11. jQuery给表单设置值
  12. UNIX网络编程——并发服务器(TCP)
  13. Java IO学习--(四)网络
  14. mysql 在visual studio中的配置
  15. css学习-》养成路线
  16. 谷歌浏览器中安装Axure扩展程序
  17. JVM五大知识点
  18. http 本地服务器设置任意IP访问对应的文件夹
  19. 远程桌面连接工具 Remote Desktop Manager 9.1.2.0 Enterprise 多国语言绿色版附注册码 简单使用
  20. 负载均衡之-LVS

热门文章

  1. 每日一个知识点:Volatile 和 CAS 的弊端之总线风暴
  2. Zookeeper 笔记小结
  3. 使用 IIS 新建WebService站点供Android访问远程sqlserver数据库
  4. 搭建 Spring 源码阅读环境
  5. python3 连接数据库~
  6. Machine Learning-特征工程之特征选择
  7. go分库分表 主从分离例子
  8. Splay浅谈
  9. Ubuntu18.04修改apt-get源
  10. iPhone手机越狱-逆向砸壳-代码注入