O método de implementar a emenda de dois arquivos em Java é o mesmo que o método de implementar o XOR de dois arquivos em Java. Os métodos FileInputStream () e FileOutputStream (). Dois arquivos do mesmo tamanho são emendados com o arquivo b após o arquivo a. O nome do arquivo de saída é outfile. Veja os seguintes detalhes para obter detalhes:
importar java.io.file; importar java.io.fileInputStream; importar java.io.filenotfoundException; importar java.io.fileOutputStream; importar java.io.ioException; classe pública append {static int count = 0; estático int countB = 0; public static void main (string args []) lança IoException {FileInputStream filea = new FileInputStream ("d: // javaxor // A"); FileInputStream fileB = new FileInputStream ("d: // javaxor // b"); Arquivo outfile = novo arquivo ("d: // javaxor // outfile"); int filesizea = filea.Available (); // Calcule o tamanho do arquivo int fileSizeB = FILEB.AVALEBLE (); FileOutputStream fos = new FileOutputStream (outfile); int hasreadA = 0; int hasReadb = 0; byte [] BUFA = novo byte [1024]; byte [] bufc = novo byte [1024]; byte [] buf_yuan = novo byte [filesizea%1024]; byte [] buf_yub = novo byte [filesizeb%1024]; while ((hasreada = filea.read (BUFA))> 0) {if (count <filesizea-filesizea%1024) {for (int i = 0; i <bufa.length && count <filesizea-fileea%1024; i ++) {bufc [i] = (byte) (bufa [i] e contagem ++; } fos.write (bufc); } else if (count> = filesizea-filesea%1024 && count <filesizea) {for (int j = 0; count> = fileSizea-fileaea%1024 && count <filesizea; j ++) {buf_yuan [j] = (byte) (bufa [j] & 0xff); contagem ++; } fos.write (buf_yuan); }} while (hasReadb = FILEB.Read (BUFA))> 0) {if (countb <filesizeb-filesizeb%1024) {for (int i = 0; i <bufa.length && countb <fileSizeBBB %B%1024; i ++) {BUFC [i] = (porte) (BUFA) (BUFA) (BUFA) (BUFA) (BURFA) (BUFA) (BUFFF; contagemb ++; } fos.write (bufc); } else if (countb> = filesizeB-Filesizeb%1024 && countb <filesizeB) {for (int j = 0; countb> = fileSizeBB-FilesizeB%1024 && countb <filesizeB; j ++) {buf_yub [j] = (byte) (bufa [j] & 0xff); contagemb ++; } fos.write (buf_yub); }}}}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.