Load a file from external storage to Inputstream

前端 未结 4 790
猫巷女王i
猫巷女王i 2020-12-25 11:47

i have a video file in my external directory. how can i load it to inputstream variable. For the time being i am reading file in the res/raw folder but i want to read it fro

相关标签:
4条回答
  • 2020-12-25 12:14
    String fileName = "OfflineMap/maps.xml";
    String path = Environment.getExternalStorageDirectory()+"/"+fileName;
    File file = new File(path);
    FileInputStream fileInputStream = new FileInputStream(file);
    
    0 讨论(0)
  • 2020-12-25 12:20

    Here is a working code, you can InputStream with a storage file:

           File sdcard = Environment.getExternalStorageDirectory();
           File file = new File(sdcard,"Demo.xml");
           InputStream fileInputStream = new FileInputStream(file);
    
    0 讨论(0)
  • 2020-12-25 12:21
    soundFile = openFileInput(uri);
    
    0 讨论(0)
  • 2020-12-25 12:24

    Try

    File file = new File(Uri.toString());
    FileInputStream fileInputStream = new FileInputStream(file);
    

    Then you can read from the stream.

    0 讨论(0)
提交回复
热议问题