Read two files, store different contents into another file, and store the other

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.