The main application is Io's randomaccessfile (I heard that resumable upload is also implemented using it)
Import java. Io .*;
Class Fen {
String filename;
Int size;
Fen (string filename, string size ){
This. filename = filename;
This. size = integer. parseint (size) * 1024;
}
Public void cut () throws exception {
Int Maxx = 0;
File infile = new file (filename );
Int filelength = (INT) infile. Length (); // get the file size
Int value; // gets the number to be split.
Randomaccessfile inn = new randomaccessfile (infile, "R"); // open the file to be split
Value = filelength/size;
Int I = 0;
Int J = 0;
// Output the file according to the number to be split
For (; j <value; j ++ ){
File OUTFILE = new file (infile. getname () + J + "zzii ");
Randomaccessfile outt = new randomaccessfile (OUTFILE, "RW ");
Maxx + = size;
For (; I <Maxx; I ++ ){
Outt. Write (Inn. Read ());
}
Outt. Close ();
}
File OUTFILE = new file (infile. getname () + J + "zzii ");
Randomaccessfile outt = new randomaccessfile (OUTFILE, "RW ");
For (; I <filelength; I ++ ){
Outt. Write (Inn. Read ());
}
Outt. Close ();
Inn. Close ();
}
}
Class he {
String filename;
String filtername;
He (string filename, string filtername ){
This. filename = filename;
This. filtername = filtername;
}
Public void unite () throws exception {
String [] tt;
File infile = new file ("."); // file in the current directory
File OUTFILE = new file (filename); // get the output name
Randomaccessfile outt = new randomaccessfile (OUTFILE, "RW ");
// Obtain the qualified file name
Tt = infile. List (New filenamefilter (){
Public Boolean accept (File Dir, string name ){
String RR = new file (name). tostring ();
Return RR. endswith (filtername );
}
});
// Print the obtained file name
For (INT I = 0; I <TT. length; I ++ ){
System. Out. println (TT [I]);
}
// Open all the files and write them into one file.
For (INT I = 0; I <TT. length; I ++ ){
Infile = new file (TT [I]);
Randomaccessfile inn = new randomaccessfile (infile, "R ");
Int C;
While (C = Inn. Read ())! =-1)
Outt. Write (C );
}
Outt. Close ();
}
}
Public class test {
Public static void main (final string [] ARGs) throws exception {
If (ARGs. Length = 0 ){
Print ();
Return;
}
If (ARGs [0]. Equals ("-c ")){
Fen cutt = new Fen (ARGs [1], argS [2]);
Cutt. Cut ();
}
Else if (ARGs [0]. Equals ("-R ")){
He Hee = new he (ARGs [1], argS [2]);
Hee. Unite ();
}
Else
Print ();
}
Public static void print (){
System. out. println ("Usage:/N points: Java test-C file1 size (unit: K)/n in combination with Java test-r file2 zzii (easy identification I set )");
}
}