byte数组和File,InputStream互转

2019-09-02 01:15:22


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


  • 2018-10-15 09:22:07

    使用epublib解析epub文件(章节内容、书籍菜单)

    前阵子在android上解析epub格式的书籍。发现了这个开源的epub解析库。相关资料甚少!折腾了一阵子,发现其实光使用的话还是挺简单的。真是萌萌哒~下面简单介绍一下epublib。

  • 2018-10-20 20:44:03

    RecycleView4种定位滚动方式演示

    将RecyclerView滑动到指定位置,或者检索RecyclerView的某一项(各个项的高度不确定),然后定位滚动这到一项,将它显示。 下面就讲解4种RecyclerView定位滚动