1

I have a videoview

 Videoview videoPlayer = findViewById(R.id.video);
 videoPlayer.setVideoURI(MY_PATH);
 videoPlayer.start();

If a video exists under MY_PATH, videoView plays it correctly, how can i catch if there is no video under MY_PATH in phone? I need to find it before calling .start(). Thanks.

ankuranurag2
  • 2,300
  • 15
  • 30
  • 1
    Possible duplicate of [Checking if a File is Blank in Android](https://stackoverflow.com/questions/17883124/checking-if-a-file-is-blank-in-android) – ADM Feb 05 '19 at 10:45
  • @stalkerstacker have you tried this -> https://stackoverflow.com/questions/10576930/trying-to-check-if-a-file-exists-in-internal-storage and this ->https://stackoverflow.com/questions/13205385/how-to-check-if-file-is-available-in-internal-memory/13207778 – Nilesh Panchal Feb 05 '19 at 10:48
  • Possible duplicate of [Android; Check if file exists without creating a new one](https://stackoverflow.com/questions/16237950/android-check-if-file-exists-without-creating-a-new-one) – ankuranurag2 Feb 05 '19 at 11:02

1 Answers1

1

If a file is blank (has no contents) its length is 0. The length returns also 0 if it doesn't exist; if this is a necessary distinction you can check if the file exists with the exists method.

File f = getFileStreamPath("test.txt");if (f.length() == 0) {// empty or doesn't exist} else { // exists and is not empty}

The current approach fails to work because inputBuffer is an array of 1024 chars, and a strings created from it will also have 1024 chars, independently of how many chars were successfully read from the file

Imran khan
  • 123
  • 1
  • 12
  • File sdcard = Environment.getExternalStorageDirectory(); File f = new File(sdcard, "/yourfile"); if(!f.exsist()){ f.createNewFile(); //Use outwriter here, outputstream search how to write into a tet file in java code } – Imran khan Feb 05 '19 at 10:52