--There's no difference in the way the byte-stream is divided, just adding the file pointer determines where to start the split ...
PackageCom.dragon.java.splitmp3;ImportJava.io.File;ImportJava.io.RandomAccessFile;ImportJava.util.Scanner; Public classTest { Public Static voidMain (string[] args)throwsException {Scanner Scanner=NewScanner (system.in); System.out.println ("Please enter the path of the file to be split:"); String FilePath=Scanner.next (); File Srcfile=NewFile (FilePath); System.out.println ("Please enter the number of copies to split:"); intn =Scanner.nextint (); Longpointer = 0; //divided into n segments, length of each segment, plus 1 to prevent data loss LongParentlength = Srcfile.length ()/n + 1; Randomaccessfile rafsrc=NewRandomaccessfile (Srcfile, "R"); for(inti = 1; I < n + 1; i++) { //the name of the segmented sub-fileRandomaccessfile Rafdec =NewRandomaccessfile (NewFile (Srcfile.getparent (),"Part" + i + "." + Srcfile.getname (). split ("\ \") [1]), "RW"); //point the file pointer to the position of the pointer when the last split was completedRafsrc.seek (pointer); byte[] buffer =New byte[(int) Parentlength]; intLen =rafsrc.read (buffer); Rafdec.write (Buffer,0, Len); Pointer=Rafsrc.getfilepointer (); } }}
--this time the partition of a MP3 file, unexpectedly found that the child files are valid, so that the audio file is stored in the same way as pictures and video files ...
Java--> using file pointers to split files