When you want to merge the contents of two files together, the first file writes a file, and then reads the next file in the write, the individual feels very simple, and the implementation code is very easy:)
1 Public voidmergetwofiles (String inpath1,string inpath2,string outpath) {2File out =NewFile (outpath);3 if(!out.exists ()) Out.mkdir ();4 5 Try {6FileReader fr1=NewFileReader (INPATH1);//read the contents of the first file7FileReader fr2=NewFileReader (INPATH2);//read the contents of a second file8BufferedReader br1=NewBufferedReader (FR1);9BufferedReader br2=NewBufferedReader (FR2);TenBufferedWriter bw3=NewBufferedWriter (NewFileWriter (OutputFile)); One String s,s1; As=br1.readline (); -s1=br2.readline (); - while(s!=NULL) the { -Bw3.write (s);//write the first file -s=br1.readline (); -Bw3.newline ();//line Break + } - while(s1!=NULL) + { ABw3.write (S1);//write the contents of the second file ats1=br2.readline (); - bw3.newline (); - } - br1.close (); - br2.close (); - bw3.close (); inSystem.out.println ("Merge Succeed ..."); -}Catch(FileNotFoundException e) { to //TODO auto-generated Catch block + e.printstacktrace (); -}Catch(IOException e) { the //TODO auto-generated Catch block * e.printstacktrace (); $ }Panax Notoginseng}
Java merge files