/*文件64位编码*/

public static void main(String[] args) {
   byte[] fileByte = toByteArray(newFile);
   String imgStr = new BASE64Encoder().encode(fileByte);
  }

/*读取文件的字节数组*/
public static byte[] toByteArray(File file) throws IOException {
File f = file;
if (!f.exists()) {
throw new FileNotFoundException("file not exists");
}
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(f));
int buf_size = 1024;
byte[] buffer = new byte[buf_size];
int len = 0;
while (-1 != (len = in.read(buffer, 0, buf_size))) {
bos.write(buffer, 0, len);
}
return bos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
throw e;
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
bos.close();
}
}

最新文章

  1. 一步一步开发Game服务器(五)地图寻路
  2. SQL Server占用内存的认识
  3. xml、文件操作功能类
  4. JS时间戳格式化日期时间 由于mysql数据库里面存储时间存的是时间戳,取出来之后,JS要格式化一下显示。
  5. HBase HMaster Architecture - HBase Master架构
  6. 多个分布式系统如何共享使用一个固定公网IP
  7. OpenReports中文支持方案
  8. ANCS协议翻译
  9. 【转】20个令人敬畏的jQuery插件
  10. 201521123020 《Java程序设计》第9周学习总结
  11. C#中的协变(Covariance)和逆变(Contravariance)
  12. 转:IT巨头纷纷“卡位” 智能语音成人机交互入口必争之地
  13. SSIS - 2.使用脚本任务弹出对话框
  14. Ultimate Facebook Messenger for Business Guide (Feb 2019)
  15. java内存分配与垃圾回收
  16. 3D Slicer Reconstruct CT/MRI
  17. impala与hive的比较以及impala的有缺点
  18. 使用定时器通过改变图片的src来切换图片
  19. 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同
  20. httpd 不带反斜杠 出现 301重定向

热门文章

  1. Java基础毕向东day05 对象与对象的区别,匿名内部类,函数的执行流程。
  2. Javascript ----字符串(String)中的方法
  3. mysql 批量创建表
  4. hdoj-2025a
  5. bistu新生-1005
  6. ModelFirst的CRUD
  7. iOS:测试机添加
  8. iOS LaunchScreen启动图设置
  9. JS获取年月日
  10. JS回车键处理