Import java.io. *; import java.util. *;
/ ** * File flow merge *
title: p> *
description: p> *
Copyright: Copyright (c) 2004 p> *
Company: p> * @author mhj * @version 1.0 * / public class CoalitionFiles {private Vector vt; private String outfile = ""; private FileInputStream in; private FileOutputStream out; private String _temp_info = ""; private int nNumber; private byte [] Buffer; private static final int bufferLength = 2048; // buffer size
Public coalitionfiles () {this.vt = new vector ();
/ ** * Set the file name to be merged, require absolute address * @Param v Vector * / public void setInputfiles (vector v) {this.vt = v;
Public void setInputfiles (string infile) {this.vt.addelement (infile);}
Public void set0file (string outfile) {this.outfile = outfile;}
Public void coalition () {if (isallowtocoalition ()) {try {// Create a file output stream object Out = new fileoutputstream (this.outfile);
// Write a merge file file information BYTE [] Bytes = (this._temp_info "/ n"). GetBytes (); out.write (bytes);
For (int i = 0; i // Close the created stream object this.ct.clear (); out.close (); in.close ();} catch (ooException e) {system.err.println ("IO Error!");}}} Private boolean isallowtocoalition () {boilean b = true; if (this.vt == null) {system.err.println ("No setting to merge file name!"); b = false;} if (this.outfile. Equals (")) {system.err.println (" No settings after you want to merge new file name! "); b = false; Long StartPOS = 0; long endpos = 0; for (int i = 0; i Return B; // public static void main (String [] args) {// coalitionFiles coalitionFiles1 = new coalitionFiles (); // vector a = new vector (); // a.addelement ("d: //test/1.txt "); // a.addelement (" d: //test//2.txt "); // a.addelement (" d: //test//1.rar "); // a.addelement (" D: //test//2.rar "); // a.addelement (" d: //test//3.rar "); // a.addelement (" d: //test//4.rar "); // a.addelement (" d: //test//5.rar "); // a.addelement (" d: //test//6.rar "); // a.addelement (" D: //test//7.rar "); // a.addelement (" D: //test//8.iso "); // a.addelement (" D: //test//9.iso "); // a.addelement (" d: //test/10.iso "); // a.addelement (" d: //test//11.io "); // coalitionFiles1.setInputFiles (A ); // coalitionFiles1.setFile ("D: // Test // AA"); // coalitionfiles1.coalition (); //}} Import java.io. *; / ** * File flow split * Title: p> * description: p> * Copyright: Copyright (C) 2004 p> * Company: < / p> * @author mhj * @version 1.0 * / public class SplitFiles {private String infile = ""; private FileInputStream in; private FileOutputStream out; private String outfiles = ""; private String outfilepath = ""; private String outfile = Private long startpos = 0; private long endpos = 0; private long lineLength = 0; private static final int buffength = 2048; // buffer size public splitfiles () {} Public void setInputfile (string file) {this.infile = file;} Public void set0filepath (string path) {this.outfilepath = path;} Public void split () {if (isAllowToPlit ()) {// First acquire merge information for merge file this.outfiles = getFilesInfo (); for (int i = 0; i //System.out.println (outfile ":" StartPOS ":" ENDPOS); Try {// Create a file input stream object instance in = new fileinputstream (this.infile); // Create a file output flow object instance out = new fileoutputstream (this.outfilepath this.outfile); Byte [] buffer = new byte [this.bufferLength]; int nNumber = 0; int _t_number = 0; in.skip (StartPOS this.LineLength 1); while ((nnumber = in.read (buffer, 0, buffer.length)! = -1) {_t_number = _t_number nNumber; if (_t_number> (endpos - startpos) {nnumber = (int) (endpos - startpos)% this.bufferLength; out.write (buffer, 0, nnumber); break;} else {out.write (buffer, 0, nnumber);}} // Close file stream object Out .close (); in .close ();} catch (ion (ooException e) {system.err.println ("IO error");}}}} / ** * is initialized * @return boolean * / private boolean isAllowToToToTSplit () {Boolean B = true; if (this.infile.equals (")) {system.err.println (" No settings to be split)! "); B = false;} IF (this.outfilepath.equals (")) {system.err.println (" There is no setup path to the file to be split! "); b = false;} File f = new file (this.infile); if (! F.exists ()) {system.err.println ("No file to be split:" f.getPath ()); b = false;} Return B; / ** * File information to be split * @Return string * / public string getFilesinfo () {string line = ""; try {fileReader fr = new fileReader (this.infile); bufferedReader Br = New BufferedReader (fr) Line = br.readline (); BYTE [] bytes = line.toString (). getBytes (); this.LineLength = bytes.length; Br.close (); fr.close ();} catch (filenotfoundexception ex) {system.out.println ("Can't find file: this.infile;} catch (ioException ex) {system.out.println ("Read the file:" this.infile "failed");} return line;} // public static void main (STRING [] args) {// splitfiles splitfiles1 = new splitfiles (); // splitfiles1.setInputFile ( "D: // Test // AA"); // splitfiles1.setoutFilePath ("D: // Test2 //"); // splitfiles1.split (); //} }