• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Weird "java.io.FileNotFoundException:" error

ar792

Newbie
In my video recording code, to implement pause functionality, 'n' no. of mp4 files are created in sequence.
(file1.mp4, file2.mp4, file3.mp4.....)

Following code is used for file name sequence; (thanks to Robpuk38):
http://androidforums.com/threads/writing-filename-in-sequence.985745/

After this, these 'n' no of files are parsed using mp4Parser:
Code:
public class MergeVide extends AsyncTask<String, Integer, String> {
        File files;

        @Override
        protected void onPreExecute() {
          

            files = new File("/storage/emulated/0//Videos/Temp/");
            File[] list = files.listFiles();
            for (File aList : list) {
                System.out.println(aList + " piece of video");
            }



        }

      

        @Override
        protected String doInBackground(String... params) {

            String[] videoUris = new String[]{

                    Arrays.toString(files.listFiles()),

            };

      
            try {
                List<Movie> inMovies = new ArrayList<Movie>();
                for (String videoUri : videoUris) {
                    inMovies.add(MovieCreator.build(videoUri));
                }
                List<Track> videoTracks = new LinkedList<Track>();
                List<Track> audioTracks = new LinkedList<Track>();
                for (Movie m : inMovies) {
                    for (Track t : m.getTracks()) {
                        if (t.getHandler().equals("soun")) {
                            audioTracks.add(t);
                        }
                        if (t.getHandler().equals("vide")) {
                            videoTracks.add(t);
                        }
                    }
                }
                Movie result = new Movie();
                if (audioTracks.size() > 0) {
                    result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
                }
                if (videoTracks.size() > 0) {
                    result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
                }
                Container out = new DefaultMp4Builder().build(result);
                FileChannel fc = new RandomAccessFile(String.format("/storage/emulated/0//output.mp4"), "rw").getChannel();
                out.writeContainer(fc);
                fc.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }



            File oldFile = new File("/storage/emulated/0//Videos/output.mp4");
            mFileName = new File("/storage/emulated/0//Videos/ video.mp4");
            boolean success = oldFile .renameTo(mFileName );

            if(success)
                System.out.println("file is renamed..");
            return String.valueOf(mFileName);
        }


All the recorded 'n' of file.mp4 are listed in the console, but I also get "java.io.FileNotFoundException:" for the same files!

CONSOLE:

/com.exapps.videorec I/System.out﹕ /storage/emulated/0/Videos/Temp/file1.mp4 piece of video
/com.exapps.videorec I/System.out﹕ /storage/emulated/0/Videos/Temp/file2.mp4 piece of video
/com.exapps.videorec I/System.out﹕ /storage/emulated/0/Videos/Temp/file3.mp4 piece of video
/com.exapps.videorec W/System.err﹕ java.io.FileNotFoundException: [/storage/emulated/0/Videos/Temp/file1.mp4, /storage/emulated/0/Videos/Temp/file2.mp4, /storage/emulated/0/Videos/Temp/file3.mp4]: open failed: ENOENT (No such file or directory)
/com.exapps.videorec W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
/com.exapps.videorec W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:76)
/com.exapps.videorec W/System.err﹕ at com.googlecode.mp4parser.FileDataSourceImpl.<init>(FileDataSourceImpl.java:19)
.................

But if i set the above code as:
Code:
String[] videoUris = new String[]{

        /storage/emulated/0/Videos/Temp/file1.mp4,
        /storage/emulated/0/Videos/Temp/file2.mp4,
        /storage/emulated/0/Videos/Temp/file3.mp4

};

It does work perfectly..

Any help appreciated..!
 
I wouldn't think that this would/should cause the issue that you're seeing (since it doesn't / won't from a Linux/Unix shell prompt), but do you see that you have a "//"(double slashes in the pathname list) in this line of code:

files = new File("/storage/emulated/0//Videos/Temp/");

right before you do the file list:

File[] list = files.listFiles();

See if removing the extra forward slash fixes things.

Cheers!
 
Good spot Alien, but I reckon here is the problem - this piece of code will not create an array of individual Strings. It will create an array of one String, which has all the file names concatenated

Code:
String[] videoUris = new String[]{
                    Arrays.toString(files.listFiles()),
            };

The variable videoUris isn't actually needed. The code can iterate over files instead

Code:
           for (File file: files) {
                    inMovies.add(MovieCreator.build(file.getPath()));
           }
 
Thanks..
The slashes aren't the issue, i have tried using a single one... the result is the same ... I'll give a try to LV426's solution,..!
 
Good spot Alien, but I reckon here is the problem - this piece of code will not create an array of individual Strings. It will create an array of one String, which has all the file names concatenated

Code:
String[] videoUris = new String[]{
                    Arrays.toString(files.listFiles()),
            };

The variable videoUris isn't actually needed. The code can iterate over files instead

Code:
           for (File file: files) {
                    inMovies.add(MovieCreator.build(file.getPath()));
           }

I am using Android Studio..

It gives an error: foreach cannot be applied to type 'java.io.File'
 
Back
Top Bottom