zoukankan      html  css  js  c++  java
  • byte数组和File,InputStream互转

    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);

  • 相关阅读:
    特殊集合
    推箱子
    集合
    数组

    循环语句 练习题
    穷举与迭代
    循环语句
    练习题
    switch case
  • 原文地址:https://www.cnblogs.com/jinglecode/p/5852211.html
Copyright © 2011-2022 走看看