The input and output stream in the javase---a read stream that corresponds to multiple output streams. And the resulting fragmented files are numbered sequentially.

Source: Internet
Author: User

<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 {/** * file cutter. * One read stream, corresponding to multiple output streams. And the resulting fragmented file has an ordered number * @param args * @throws ioexception */private static final int default_size=1024*2;public static void Ma In (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 Ioexceptio        n {if (!srcfile.exists ()) {throw new RuntimeException (Srcfile.getabsolutepath () + ", source file does not exist");} if (!destdir.exists ()) {destdir.mkdirs ();} 1. Define a source file FileInputStream fis=new FileInputStream (srcfile);//2, create purpose reference FileOutputStream FOS=NULL;//3, Create a buffer to store data byte[] buf=new byte[default_size];int len=0;int count=0;while (leN=fis.read (BUF))!=-1) {//create an output stream and clear the file to be written to files Partfile=new (DestDir, (++count) + ". Part"); Fos=new FileOutputStream (partfile); Fos.write (buf, 0, Len); Fos.close ();} When producing fragmented files, you need to generate a configuration file that records the number of fragments and the key value information stored in the source file name//partfile=n;filename=11.avi//configuration file. Use the Properties collection Properties Prop=new properties ();p rop.setproperty ("Partcount", integer.tostring (count)); Prop.setproperty ("filename", srcfile.getname ()); File Confile=new file (DestDir, (++count) + ". Properties"), Fos=new FileOutputStream (confile);//Close Resource fos.close (); Fis.close ();}} </span>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The input and output stream in the javase---a read stream that corresponds to multiple output streams. And the resulting fragmented files are numbered sequentially.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.