Java file Cutting, why the error when closing the stream, 51 lines

Source: Internet
Author: User

1  PackageJava_io. Test_1.file_split_and_sequecedemo;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 ImportJava.io.FileOutputStream;6 Importjava.io.IOException;7 8  Public classFilesplit {9 Ten     Privatefile file; One     Private intsize; A  -      PublicFilesplit (File file,intsize) { -         //TODO auto-generated Constructor stub the          This. File =file; -          This. Size = Size * 1024 * 1024; -  -     } +  -      Public voidSpliting ()throwsIOException { +         //TODO auto-generated Method Stub A  at         //Read source file -FileInputStream FIS =Newfileinputstream (file); -  -         //Create a fragmented file directory, if the fragmented directory does not exist just created -File dir =NewFile (File.getparent (), "Filespart"); -         if(!dir.exists ()) { in dir.mkdirs (); -         } to  +         //Create buffers -         byte[] BUFB =New byte[1024 * 1024]; the         intLen = 0; *  $          for(inti = 1;; i++) {Panax Notoginseng             intSumsize = 0; -File Filepart =NewFile (dir, i + ". Part"); theFileOutputStream fos =NewFileOutputStream (filepart); +              while(Sumsize <size) { A                 if(len = Fis.read (BUFB))! =-1) { theFos.write (BUFB, 0, Len); +Sumsize + =Len; -                 } $  $             } - fos.close (); -  the              -         }Wuyi fis.close (); the          -          Wu     } -      About          $}

The above code implements a file cutting function, the constructor parameter file is to receive the files to be cut, the size of each fragment file specified by the user, the problem is that the last time I was 51 lines to close the read file stream, error, say what compile error. Ask a great God for guidance. If you can read the message to me

Java file Cutting, why the error when closing the stream, 51 lines

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.