文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号...
生活随笔
收集整理的這篇文章主要介紹了
文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号...
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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 *//** 文件分割器,* 一個(gè)讀取流,相應(yīng)多個(gè)輸出流。并且生成的碎片文件都有有序的編號(hào)*/public static void main(String[] args) throws IOException {File destdir = new File("teampFile\\filepart");File file = new File("E:\\A-Lin - 給我一個(gè)理由忘記.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();}}
總結(jié)
以上是生活随笔為你收集整理的文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【性能优化】直方图
- 下一篇: 2015 ICL, Finals, Di