Load a file from external storage to Inputstream

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 from the sdcard. also i dont know about the name of the file but its path will be recieved through intent.
check the following code

public class SonicTest extends Activity
VideoView videoView;
String uri;
InputStream soundFile;
File file;
public void onCreate(Bundle savedInstanceState) 


public void play(View view)
    new Thread(new Runnable() 
        public void run()
            float speed= (float) 1.0;
            float pitch= (float) 1.5;
            float rate= (float) 1.0;
            uri= Environment.getExternalStorageDirectory().toString();
            AndroidAudioDevice device = new AndroidAudioDevice(22050, 1);
            Sonic sonic = new Sonic(22050, 1);
            byte samples[] = new byte[4096];
            byte modifiedSamples[] = new byte[2048];
            InputStream soundFile = null;

    //soundFile = getContentResolver().openInputStream(Uri.parse(uri));
    Log.i("testing","check if SoundFile is correct "+soundFile);

            int bytesRead;

            if(soundFile != null) {
                do {
                    try {
                        bytesRead = soundFile.read(samples, 0, samples.length);
                    } catch (IOException e) {
                    if(bytesRead > 0) {
                        sonic.putBytes(samples, bytesRead);
                    } else {
                    int available = sonic.availableBytes(); 
                    if(available > 0) {
                        if(modifiedSamples.length < available) {
                            modifiedSamples = new byte[available*2];
                        sonic.receiveBytes(modifiedSamples, available);
                        device.writeSamples(modifiedSamples, available);
                } while(bytesRead > 0);
    } ).start();

  • Android Google Maps v2 - set zoom level for myLocation
  • How to implement dialog like truecaller in android
  • When would one use the BRICK permission?
  • adb.exe start server failed android studio
  • Android Studio 1.0.1 add external libraries
  • Android : How to programatically open the soft keyboard in Emoji View
  • Ormlite or sqlite Which one is good for Android perspective?
  • How do I clone a View?
  • How to receive a event on android checkbox check change?
  • Bitmap allocation, using BitmapFactory.Options.inBitmap throws IllegalArgumentException
  • Android: Detecting USB
  • android progressBar does not update progress view/drawable
  • 3 Solutions collect form web for “Load a file from external storage to Inputstream”


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

    Then you can read from the stream.

    String fileName = "OfflineMap/maps.xml";
    String path = Environment.getExternalStorageDirectory()+"/"+fileName;
    File file = new File(path);
    FileInputStream fileInputStream = new FileInputStream(file);
    soundFile = openFileInput(uri);
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.