IO流之檔案切割,檔案合并 Java

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.