Io stream file cut, file merge Java

Source: Internet
Author: User

Existing requirements, a designated PPT of the desktop according to the size of 1MB to cut, will cut out the files and configuration files in a directory

ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;Importjava.util.Properties; Public classTest { Public Static voidMain (string[] args)throwsIOException {File file=NewFile ("C:\\users\\fan\\desktop\\product. PPT ");    Splitfile (file); }     Public Static voidSplitfile (File file)throwsIOException {//The byte array is 1024*1024 in length, and the size is 1MB when the array is filled.        Final intsize=1024*1024; //putting configuration information in the properties containerProperties pro=NewProperties (); //associating source files with read streamsFileInputStream fis=Newfileinputstream (file); //Custom Buffer Arrays        byte[] buf=New byte[size]; //Purpose of CreationFileOutputStream fos=NULL; intLen=0; intCount=1; //declare a directory to hold the cut filesFile dir=NewFile ("C:\\users\\fan\\desktop\\partfiles"); //If the directory does not exist, create the        if(!dir.exists ()) dir.mkdirs ();  while((Len=fis.read (BUF))!=-1) {fos=NewFileOutputStream (NewFile (dir, (count++) + ". Part")); Fos.write (BUF,0, Len);        Fos.close (); } pro.setproperty ("Partcount", count+ ""); Pro.setproperty ("FileName", File.getname ()); FOS=NewFileOutputStream (NewFile (dir,count+ ". Properties")); Pro.store (FOS,"Save");        Fos.close ();    Fis.close (); }}

Io stream file cut, file merge Java

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.