1、将File、FileInputStream 转换为byte数组:

File file = new File("file.txt");

InputStream input = new FileInputStream(file);

byte[] byt = new byte[input.available()];

input.read(byt);

2、将byte数组转换为InputStream:

byte[] byt = new byte[1024];

InputStream input = new ByteArrayInputStream(byt);

3、将byte数组转换为File:

File file = new File('');

OutputStream output = new FileOutputStream(file);

BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);

bufferedOutput.write(byt);

byte数组和File,InputStream互转的更多相关文章

  1. InputStream,BufferedImage与byte数组之间的转换

    需要获取网络的一张图片,但是某种需要,要把获取的这段流输入换为BufferedImage流,有的地方还需要转换为byte[]. 获得图片地址,获得了一个图片输入流,例如:    Url img = n ...

  2. java byte数组与String互转

      java byte数组与String互转 CreationTime--2018年7月6日14点53分 Author:Marydon 1.String-->byte[] 方法:使用String ...

  3. java File和Byte[]数组 相互转换

    public class Test { public static void main(String[] args){ String filePath = "E:\\softoon\\wor ...

  4. 将文件File转换成byte数组

    代码如下: /** * 将文件转换成byte数组 * @param filePath * @return */ public static byte[] File2byte(File tradeFil ...

  5. Golang十六进制字符串和byte数组互转

    Golang十六进制字符串和byte数组互转 需求 Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包 实现Demo package main i ...

  6. int跟byte[]数组互转的方法,整数 + 浮点型

    整数: int转byte数组 public static byte[] intToBytes2(int n){ ]; ;i < ;i++) { b[i]=(-i*)); } return b; ...

  7. 字符串、十六进制、byte数组互转

    import java.io.ByteArrayOutputStream; public class HexUtil { /** * @param args */ public static void ...

  8. 二进制样式的字符串与byte数组互转函数示例

    开发时用到的方法,记录下: /// <summary> /// 测试方法 /// </summary> private void TestFun() { Response.Wr ...

  9. 可序列化对象和byte[]数组之间的互转

    /// <summary> /// 将可序列化对象转成Byte数组 /// </summary> /// <param name="obj">对 ...

随机推荐

  1. 跳转Activity两种方法

    摘要:假设从A界面开启另外一个B界面根据是否需要返回数据分为两种方式 一.无需返回数据方式 在A界面中调用startActivity方法进行直接跳转即可 二.需要返回数据方式 1.在A界面中调用sta ...

  2. CM12.1/13.0编译教程

    环境搭建 1.安装64位Ubuntu系统(实体安装.虚拟机安装均可) 注意:要求机器至少4G内存(虚拟机至少分配4G内存),硬盘至少100G空间(源码20G+,编译后整个目录约60~70G) 安装方法 ...

  3. MongoDB Node.js driver

    Node.js连接MongoDB的简单实例 安装Node.js driver npm install mongodb -save 连接 var MongodbClient = require('mon ...

  4. <<< jquery简介、开头语法、在线开发手册

    简介 jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多).jQuery在2006年1月由美国人John Resig在纽约的b ...

  5. linux下centos的网络连接

  6. ubuntu14.04 下安装有道词典

    安装步骤 1.ubuntu14.04.1版本下是不能直接安装有道词典的,首先需要把14.04.版升级为14.04.2版. 在终端窗口中输入以下命令: sudo apt-get update sudo ...

  7. QQ空间爬虫最新分享,一天 400 万条数据(附代码地址)

    http://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&mid=2653552228&idx=1&sn=e476bf23556406c ...

  8. Java数据结构——图

    点 //类名:Vertex //属性: //方法: class Vertex{ public char label; //点的名称,如A public boolean wasVisited; publ ...

  9. 浅谈Android中拍照、从相册选择图片并截图相关知识点

    前言 我们在Android开发中经常会需要使用相机或者从相册中选取图片的情况,今天就把这里面相关的知识点总结下,方便以后开发的时候使用. 1.相机拍照并可自定义截图功能 我们先来看如何使用Intent ...

  10. [Head First设计模式]策略模式

    系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...