将多个文件合并为一个文件
生活随笔
收集整理的這篇文章主要介紹了
将多个文件合并为一个文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
例:將由MP3文件拆分的四個(gè)文件合并為原來的文件
代碼如下:
package work2;import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException;public class CombinDemo {public static void main(String[] args) {BufferedOutputStream bos = null;// TODO Auto-generated method stubtry {bos = new BufferedOutputStream(new FileOutputStream("copy.mp3"));for (int i = 1; i <= 4; i++) {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\mp3.m4a" + i));byte[] buf = new byte[1024 * 200];int len = bis.read(buf);bos.write(buf, 0, len);bis.close();}System.out.println("合并成功");} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (bos != null) {try {bos.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}}注:主頁更多學(xué)習(xí)資料。
總結(jié)
以上是生活随笔為你收集整理的将多个文件合并为一个文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 采用直线逼近方式的圆弧插补
- 下一篇: JAVA调用打印机,打印PDF文件