Die Methode zur Implementierung des Spleißens von zwei Dateien in Java entspricht der Methode zur Implementierung des XOR von zwei Dateien in Java. Sowohl FileInputStream () als auch FileOutputStream () -Methoden. Zwei Dateien derselben Größe werden mit Datei B nach Datei a gespleißt. Der Ausgabedatei -Name ist Outfile. Weitere Informationen finden Sie in den folgenden Details:
importieren java.io.file; import java.io.fileinputstream; import java.io.filenotfoundException; import Java.io.FileOutputStream; import Java.io.ioException; öffentliche Klasse append {static int count = 0; static int countb = 0; public static void main (String args []) löst IOException {FileInputStream filea = new FileInputStream ("d: // javaxor // a") aus; FileInputStream FileB = new FileInputStream ("d: // javaxor // b"); Datei outfile = new Datei ("d: // javaxor // outfile"); int fileizea = filea.available (); // Berechnen Sie die Dateigröße int afideB = fileB.available (); FileOutputStream fos = new FileOutputStream (Outfile); int hasreada = 0; int hasReadb = 0; byte [] bufa = neues byte [1024]; byte [] bufc = neues byte [1024]; byte [] buf_yuan = new byte [fileizea%1024]; byte [] buf_yub = new byte [ideSizeB%1024]; while ((hasReada = filea.read (bufa))> 0) {if (count <filesiea-filea%1024) {für (int i = 0; i <bufa.length && count <filesinea-filea%1024; i ++) {bufc [i] = (byte) (bufa [i] & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) & 0xff) (bufa [i] (bufa [i] (bufa [i] (bufa [i] (bufa) & 0xff) & 0xff) & 0xff) & 0xff; zählen ++; } fos.write (bufc); } else if (count> = fileizea-filesiea%1024 && count <fileizea) {für (int j = 0; count> = fileizea-filea%1024 && count <fileizea; j ++) {buf_yuan [j] = (byte) (bufa [j] & 0xff); zählen ++; } fos.write (buf_yuan); }} while ((hasReadb = fileB.Read (bufa))> 0) {if (countb <fileSizeSizeB%1024) {für (int i = 0; i <bufa.Length && countb <ideSizeB-fileSize-%1024; i ++) {bufc [i] (bufc [i] (bufc) (bufc) (bufc [i] (buf) (bufc) (bufc) (bufc) (bufc) (bufc) (bufc) (bufc) (bufc) (bufc); countb ++; } fos.write (bufc); } else if (countb> = ideSizeB-fileSizeB%1024 && countb <ideSizeB) {für (int j = 0; countb> = ideSizeB-fileSize%1024 && countb <idesizeB; j ++) {buf_yub [j] = (byte) (bufa [j] & 0xff); countb ++; } fos.write (buf_yub); }}}}Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.