File cutter, one read stream, corresponding to multiple output streams, and the resulting fragmented files are numbered sequentially

Source: Internet
Author: User

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 *//* * File Cutter, * One read stream, corresponding to multiple output streams, and the resulting fragmented file has an ordered number */public static void Main (string[] args) throws IOException {File Destdir = new File ("Teampfile\\filepart");     File File = new file ("E:\\a-lin-give me a reason to forget. mp3"); Filesplite (File,destdir);} private static void Filesplite (file file, file Destdir) throws IOException {if (!file.exists ()) {throw new runtimeexception   (destdir+ "file does not exist");} 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 Fileoutputstrea M (partfile); Fos.write (Buf,0,len); Fos.close ();} Properties Prop =new Properties ();p ROP.SetProperty ("Partcount", integer.tostring (count));p rop.setproperty ("filename", file.getname ()); File profile = new file (Destdir, (++count) + ". Properties"), Fos=new fileoutputstream (profile);p rop.store (FOS, "save"); Fos.close ();}}

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

File cutter, one read stream, corresponding 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.