java - File management with BufferedInput/OutputStream -


i'm using bufferedinputstream , bufferedoutputstream copy mp4 video programatically. it's being correctly copied, except because lose audio! code:

    fileinputstream fi = null;     fileoutputstream fo = null;     try {         file f = new file("c:\\users\\zerok\\videos\\v.mp4");         fi = new fileinputstream(f);         fo = new fileoutputstream("video.mp4");         bufferedinputstream buffin = new bufferedinputstream(fi);         bufferedoutputstream buffout = new bufferedoutputstream(fo);          int read;         while((read = buffin.read()) != -1){             buffout.write(read);         }      } catch (filenotfoundexception ex) {         logger.getlogger(javaapplication13.class.getname()).log(level.severe, null, ex);     } catch (ioexception ex) {         logger.getlogger(javaapplication13.class.getname()).log(level.severe, null, ex);     } {         try {             fi.close();         } catch (ioexception ex) {             logger.getlogger(javaapplication13.class.getname()).log(level.severe, null, ex);         }     } 

the video.mp4 file works except of audio lack. what's causing this? i'm using these classes correctly?

the problem was, wasn't closing bufferedoutputstream. used try-with-resources block, automatically closes resource once it's finished:

 try (bufferedoutputstream buffout = new bufferedoutputstream(fo)) {                 int read;                 system.out.println("beginning copy...");                 while((read = buffin.read()) != -1){                     buffout.write(read);                 }             } 

now audio reproduces perfectly.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -