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