Read two files, store different contents into another file, and store the other
<? Php/*** read data from two. CSV files * compare the data of these two files and save it to The. CSV file */class Readfiledata {private function _ construct () {}/*** read the file and obtain data */private static function getdata ($ file) {$ handle = fopen ($ file, 'R '); $ orderform = array (); $ I = 0; while (false! = ($ Data = fgetcsv ($ handle, 0, ',') {$ I ++; if ($ I = 1) continue; $ orderform [] = trim ($ data [0], ''');} fclose ($ handle); return $ orderform ;} /*** get different data from two files ** @ param String $ file1 * @ param String $ file2 */private static function getdiffdata ($ file1, $ file2) {$ orderform = self: getdata ($ file1); $ orderform2 = self: getdata ($ file2); $ diff1 = array_diff ($ orderform, $ orderform2 ); $ diff2 = array_d Iff ($ orderform2, $ orderform); $ todiff = array_merge ($ diff1, $ diff2); $ todif = array_unique ($ todiff); return $ todif ;} /*** write data into the. CSV file ** @ param String $ filename * @ param String $ file1 * @ param String $ file2 */private static function writefile ($ filename, $ file1, $ file2) {$ todiffdata = self: getdiffdata ($ file1, $ file2); $ partdata = array (); foreach ($ todiffdata as $ val) {$ partdata = array ($ val); $ newa Rray [] = $ partdata;} if (! Is_file ("/tmp/$ filename") {// unlink ("/tmp/$ filename"); touch ("/tmp/$ filename ");} $ handle = fopen ("/tmp/$ filename", 'w'); foreach ($ newarray as $ value) {fputcsv ($ handle, $ value );} fclose ($ handle);}/*** entry file */public static function main ($ filename, $ file1, $ file2) {self: writefile ($ filename, $ file1, $ file2) ;}}$ filename = 'total.csv '; $ file1 = 'ac.csv'; $ file2 = 'ad.csv '; Readfiledata: main ($ filename, $ file1, $ file2 );
Java directly reads a file and writes the read content to another file. The file content changes.
New String (content)
The file is a binary file. If you want to encode or read binary strings, some binary files are not recognized. Therefore, the system automatically performs transcoding, the binary value will change after transcoding, so you can use byte [] to copy the file.
C ++: open a file, read two characters in the file at a time, encrypt the file, and save the encrypted content to another file.
Do not put it in a vector, because make sure that the data is cleared. It is best to fix an array and relay uses the same Array for encryption.