Java
Chilkat2 Java
Split File into Chunks
Demonstrates how to split a file into chunks.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.FileAccess;
public class ChilkatExample {
public static void main(String[] args) {
FileAccess fac = new FileAccess();
// Any type of file may be split. It doesn't matter if it's
// a binary file or a text file.
String fileToSplit = "qa_data/hamlet.xml";
String partPrefix = "hamlet";
String partExtension = "part";
int maxChunkSize = 50000;
String destDirPath = "qa_output";
// Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
// Output files are written to the current working directory.
// Each chunk will be 50000 bytes except for the last which
// will be the remainder.
try {
fac.splitFile(fileToSplit, partPrefix, partExtension, maxChunkSize, destDirPath);
System.out.println("Success.");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
}
}
}