javaSE中的輸入輸出資料流---一個讀取流,對應多個輸出資料流。而且產生的片段檔案都有有序的編號,javase輸出資料流

來源:互聯網
上載者:User

javaSE中的輸入輸出資料流---一個讀取流,對應多個輸出資料流。而且產生的片段檔案都有有序的編號,javase輸出資料流

<span style="font-size:18px;">package com.io.other.split;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 SplitFileTest {/** * 檔案切割器。 * 一個讀取流,對應多個輸出資料流。而且產生的片段檔案都有有序的編號 * @param args * @throws IOException  */private static final int DEFAULT_SIZE=1024*2;public static void main(String[] args) throws IOException {File srcFile=new File("chen\\11.avi");File destDir=new File("chen\\partfiles");SplitFile(srcFile,destDir);}/** *  * @param srcFile * @throws IOException  */public static void SplitFile(File srcFile,File destDir) throws IOException {if (!srcFile.exists()) {throw new RuntimeException(srcFile.getAbsolutePath()+",源檔案不存在");}        if(!destDir.exists()){destDir.mkdirs();}//1、定義一個源檔案FileInputStream fis=new FileInputStream(srcFile);//2、建立目的引用FileOutputStream fos=null;//3、建立一個緩衝區儲存資料byte[] buf=new byte[DEFAULT_SIZE];int len=0;int count=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();}//在產生片段檔案時,需要產生一個設定檔,記錄片段的個數和源檔案名稱字//partfile=n;filename=11.avi//設定檔中儲存的索引值資訊。使用Properties集合Properties prop=new Properties();prop.setProperty("partcount", Integer.toString(count));prop.setProperty("filename", srcFile.getName());File conFile=new File(destDir,(++count)+".properties");fos=new FileOutputStream(conFile);//關閉資源fos.close();fis.close();}}</span>

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.