文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号
2016-04-15 21:19
267 查看
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(); } }
相关文章推荐
- Skinned Mesh 原理解析和一个最简单的实现示例
- 判断出栈顺序的合法性(面试题)
- Android:密码显示隐藏
- HDU 1166 敌兵布阵
- showPopupWindow 类似微信+
- XCode升级导致的IAP失败的问题
- 首尾相接的数组的子数组的最大值
- 凸包。
- 消息队列
- ARC无效时block的赋值
- 汉诺塔问题递归解法
- CSS3 @keyframes 规则
- Android(三)----数据存储和界面展现02
- Android:利用SharedPreferences实现自动登录
- Program2_1011
- 3. NHibernate基础知识 - 你必须知道的一些事情
- eclipse maven 项目导出为 jar 包
- CSS 在编写时要注意的15个问题
- 数据库连接及操作
- Lightoj1393(博弈+NIM)