文件切割器,一个读取流,对应多个输出流,而且生成的碎片文件都有有序的编号
2015-07-14 10:54
351 查看
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class FileSpilte { /** * @param args * @throws IOException */ /* * 文件切割器, * 一个读取流,对应多个输出流,而且生成的碎片文件都有有序的编号 */ public static void main(String[] args) throws IOException { File destdir = new File("teampFile\\filepart"); File file = new File("E:\\A-Lin - 给我一个理由忘记.mp3"); fileSplite(file,destdir); } private static void fileSplite(File file, File destdir) throws IOException { if(!file.exists()){ throw new RuntimeException(destdir+"文件不存在"); } if(!destdir.exists()) { destdir.mkdirs(); } FileInputStream fis = new FileInputStream(file); FileOutputStream fos = null; byte[] buf =new byte[1024*1024]; int count = 0; int len = 0; while((len=fis.read(buf))!=-1){ File partfile = new File(destdir,(++count)+".part"); fos = new FileOutputStream(partfile); fos.write(buf,0,len); fos.close(); } Properties prop =new Properties(); prop.setProperty("partcount",Integer.toString(count)); prop.setProperty("filename", file.getName()); File profile = new File(destdir,(++count)+".properties"); fos=new FileOutputStream(profile); prop.store(fos, "save"); fos.close(); } }
相关文章推荐
- Android 图片(文件--带参数)批量上传到服务器
- havok物理引擎快速入门指南翻译
- SQL_常用函数
- windows编ffmpeg2.2.4和插件h265
- 阿里云Linux服务器环境配置
- 多线程笔记4
- eclipse安装svn插件
- hdu 1384 Intervals (差分约束)
- MarkDown语法
- LLVM的简单入手步骤
- SQL基本语句
- sql:根据字段查询表名
- jQuery(function(){...})与(function($){...})(jQuery)的“兄弟”情结
- 随机森林的学习
- [LeetCode] Pascal's Triangle II
- Android 在项目中实现百度地图
- Android多线程下安全访问数据库
- 【VB】SQL多条件查询(机房问题)
- Assertion failure in -[UICGColor encodeWithCoder:]
- InputStream用法