IO:字节流截取音乐
来源:互联网 发布:淘宝好友在哪里看 编辑:程序博客网 时间:2024/06/03 21:08
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* 截取一个音乐的高潮部分
*
*/
public class CutMusic {
// start=40*320*1024/8 = 1,638,400
// end=82*320*1024/8 = 3,358,720
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
int start = 1638400;
int end = 3358720;
try {
bos = new BufferedOutputStream(new FileOutputStream("E:\\music\\截取.mp3"));
bis = new BufferedInputStream(new FileInputStream("E:\\music\\待截取.mp3"));
byte[] b = new byte[512];
int len = 0;
int total = 0;
while ((len = bis.read(b)) != -1) {
total += len;
// 如果小于开始字节的就抛弃掉
if (total < start) {
continue;
}
bos.write(b);
// 如果大于 结尾字节数 就终止读取
if (total >= end) {
bos.flush();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bos != null) bos.close();
if (bis != null) bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* 截取一个音乐的高潮部分
*
*/
public class CutMusic {
public static void main(String[] args) {
// start=40*320*1024/8 = 1,638,400
// end=82*320*1024/8 = 3,358,720
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
int start = 1638400;
int end = 3358720;
try {
bos = new BufferedOutputStream(new FileOutputStream("E:\\music\\截取.mp3"));
bis = new BufferedInputStream(new FileInputStream("E:\\music\\待截取.mp3"));
byte[] b = new byte[512];
int len = 0;
int total = 0;
while ((len = bis.read(b)) != -1) {
total += len;
// 如果小于开始字节的就抛弃掉
if (total < start) {
continue;
}
bos.write(b);
// 如果大于 结尾字节数 就终止读取
if (total >= end) {
bos.flush();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bos != null) bos.close();
if (bis != null) bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
0 0
- IO:字节流截取音乐
- IO练习--按字节截取字符串
- 24-IO流-70-IO流(练习-按字节截取字符串)
- JAVA IO流(字节流读写File(文本、图片、音乐~))
- IO流(字节流)
- IO流字节流
- IO流字节流
- IO流-字节流
- IO流--字节流
- IO之字节流
- IO字节流
- java14-IO字节流
- IO之字节流
- IO之字节流
- IO一:字节流
- IO之字节流
- IO 字节流学习
- Java IO 字节流
- Android onTouch事件解析
- Eclipse快捷键
- Memcache的使用和协议分析详解
- 菜鸟柳基础经典案例--金字塔形输出打印
- 4.15初上 Linux
- IO:字节流截取音乐
- GIT的安装和使用简介
- Eclipse创建新的server
- 用PHP实现一个关于德州扑克算法的程序(三):顺子
- KMP
- 摆动排序
- KMP
- IPython(jupyter)简单介绍和基本交互操作
- 【jzoj5060】【GDOI2017第二轮模拟day1】【公路建设】【数据结构】