黑马程序员技术交流社区

标题: io,求大神帮帮,今天老师留的作业 [打印本页]

作者: 李彭    时间: 2016-7-15 22:15
标题: io,求大神帮帮,今天老师留的作业
有3段音乐.mp3的格式拼接在一起,存放在当前项目下(没有音乐可以找音乐,名字自己改成自己想要的)

作者: 夏萱    时间: 2016-7-16 01:20
去学了一下IO,你开三个Input 一个Output,三个都分别放到这个Output里就可以了
作者: empty3717    时间: 2016-7-16 12:15
二楼正解。
作者: 15242694137    时间: 2016-7-16 15:35
这很简单吧
作者: longforus    时间: 2016-7-16 17:38
我在想這样拼接出来还能不能播放呢?
我就实验了一下结果是:

可以的

  1. import java.io.*;

  2. /**
  3. * Created by Void Young on 5:30 PM 7/16/2016 .
  4. * IDEA-Test .
  5. */
  6. public class TestMusic {
  7.     public static void main (String[] args) throws IOException{
  8.         try(
  9.                 BufferedInputStream bis1 = new BufferedInputStream (new FileInputStream ("z:/1.mp3"));
  10.                 BufferedInputStream bis2 = new BufferedInputStream (new FileInputStream ("z:/2.mp3"));
  11.                 BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream ("z:/3.mp3"));
  12.                 ) {
  13.                 int b;
  14.             while (( b = bis1.read () ) != - 1) {
  15.                 bos.write (b);
  16.             }
  17.             while (( b = bis2.read () ) != - 1) {
  18.                 bos.write (b);
  19.             }
  20.         }
  21.     }
  22. }
复制代码

作者: 地狱蓝枫    时间: 2016-7-17 19:15
学习了~~




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2