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


  • 2021-01-24 09:50:16

    UICollectionViewCell cell高度自适应

    本来想使用UICollectionView来作为整体的布局,并且不再使用UITableView,但是发现高度不固定的布局,UICollectionView没啥优势呀,至少我没找到好的方法,从网上看的是,要自定义cell,并且继承preferredLayoutAttributesFittingAttributes

  • 2021-01-24 10:08:57

    ios后台播放视频

    很多开发者以为AVPlayer不能在后台播放视频:应用退到后台,但能播放视频的声音(ps:不是通过切换相同的音频来实现),我在开发SDK的过程中也遇到这个需求,所幸解决了这个问题。下面我就来讲讲实现的过程。

  • 2021-01-24 10:10:22

    XCode提示build successed,无法启动模拟器

    使用phonegap(cordova)创建项目后,开始时使用Xcode6.1或命令行运行项目都可启动模拟器调试;不知道什么原因命令行运行项目完全没有问题,但是Xcode运行,提示build successed,但是始终无法启动模拟器。