標籤:oid style tst null 檔案 資訊 合并 desktop product
現有一要求,將案頭的一個指定PPT按照大小為1MB進行切割,將切割完的檔案及設定檔放在一個目錄中
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 test { public static void main(String[] args) throws IOException { File file=new File("C:\\Users\\fan\\Desktop\\product.PPT"); splitFile(file); } public static void splitFile(File file) throws IOException { //byte數組長度為1024*1024,數組裝滿後大小就為1MB final int size=1024*1024; //將配置資訊放入properties容器中 Properties pro=new Properties(); //用讀取流關聯源檔案 FileInputStream fis=new FileInputStream(file); //自訂緩衝數組 byte[] buf=new byte[size]; //建立目的 FileOutputStream fos=null; int len=0; int count=1; //聲明一個用於存放切割檔案的目錄 File dir=new File("c:\\users\\fan\\desktop\\partfiles"); //若目錄不存在,建立之 if(!dir.exists()) dir.mkdirs(); while((len=fis.read(buf))!=-1) { fos=new FileOutputStream(new File(dir,(count++)+".part")); fos.write(buf,0,len); fos.close(); } pro.setProperty("partcount",count+""); pro.setProperty("filename",file.getName()); fos=new FileOutputStream(new File(dir,count+".properties")); pro.store(fos,"save"); fos.close(); fis.close(); }}
IO流之檔案切割,檔案合并 Java