Php file read/write operations
// Note that it does not exist before 4.0.0-RC2! = Operator
If ($ handle = opendir ('/path/to/Files ')){
Echo "Directory handle: $ handle \ n ";
Echo "Files: \ n ";
While (false! ==( $ File = readdir ($ handle ))){
Echo "$ f
This article mainly for you to share a Python read CSV file to remove a column and then write a new file instance, has a very valuable reference, I hope to help you. Follow the small part together to see it, hope to help everyone better grasp the python
Two ways to solve the problem are the existing solutions on the Web.
Scenario Description:
There is a data
");ExitBreakCase 5:$FP 5=fopen ("F5.dat", ' R ');$oname = fgets ($fp 5);$nname = Date ("Ymdhis");Rename ($oname, $nname);Fclose ($fp 5);Unlink ("F5.dat");$FP 5=fopen ("F5.dat", ' W ');Fwrite($fp 5, $nname);Fclose ($fp 5);Header ("Location:". $nname. " /5.html ");ExitBreakDefaultBreak}?>
A part of the code in a project that has just been done includes the generat
PHP file read/write operations. PHP provides a series of I/O functions for file read/write operations, which can be simple to implement, including file system operations and directory operations (such as copying [copy]). The following section describes
PHP
PHP file read/write operations
PHP provides a series of I/O functions to implement the functions we need, including file system operations and directory operations (such as "copy [copy]"). The following describes basic file read/write operations: (1) reading files; (2) Writ
Read the file:The traditional method of reading. All read out, processed by line:Fp=open ("./ps.txt", "R");Alllines=fp.readlines ();Fp.close ();For Eachline in Alllines:Print EachlineThe recommended read method, using a file iterator, is to read and display only one row at a
, so the definition of the output stream object Ofstream Outfile,outfile is the output stream object, which is used to store the data will be written to the file. Specific practices:1 ofstream outfile; 2Outfile.open ("Myfile.bat");//Myfile.bat is the file name that holds the data3 if(Outfile.is_open ())4 { 5outfile//message is the data processed in the program6 Outfile.close (); 7 } 8 Else 9 { Tencout"c
SQLite data files
From the running results of the above code, it can be seen that the result of the data query is a list composed of tuple. Python's list data can be inconvenient when it comes to further data processing and analysis. Imagine that if there are 1 million rows or more of data in a table in a database, iterating through the list to fetch data is inefficient.
At this point, we can consider using the function provided by pandas to
(inttostr (Num); // 5 showmessage (carr2); // ABCDE closefile (f); end; // write a long string, read its hexadecimal code procedure tform1.button6click (Sender: tobject); var P: pchar; B: byte; begin P: = 'in case of Delphi blog'; assignfile (F, filename); // associated file name rewrite (F, 1); // create and open blockwrite (F, P, length (p); // write filemode: = fmopenread; // you can set the
#include DescriptionIn file F1.dat, n is provided (n is a very large number that is not required in the program) and a positive integer.Please compile the program. The maximum value in the number of top N (nThe first 10 data in F1.dat, such as the following, are in the process of debugging a program. A self-built F1.dat
, it is created. If the file already exists, it is written after the original file content.
Add the new content, and the pointer is always at the end.Ios: trunc = 0 × 10, // cut the file length to 0 (default) before reading and writing)Ios: nocreate = 0 × 20, // an error occurs when the file does not exist. It is often
: nocreate); // the default format is ios: in.Open the file. The operation fails if the file does not exist.Ofstream f ("d: 12.txt"); // The default value is ios: out.Open a fileFstream f ("d: 12. dat", ios: in | ios: out | ios: binary); // enable binary in read/write modeFileUse Open member functio
inherits from the Object class rather than the InputStream/OutputStream class) can read and write data in any position of the file (only the pointer to the file's read/write position needs to be changed ).The basic process of random file read/write programming is:① Generate
, fprintf, You only need to keep the file content consistent with the processing function. Do not worry about the mode in which the file is opened !!If you use Today, I finally figured out how to use C ++ to read and write binary files.The file to be read must contain the Yo
see how much data is written in real time.
Read the CSV file as Dataframe
Code
# Read the CSV file for Dataframeimport pandas as Pddframe = PD. Dataframe.from_csv (' E:/iris.csv ')
You can also have a slightly zigzag point:
Import Csvimport
a file
Specify the file name and open mode when calling the constructor.
Ifstream f ("d: 12.txt", ios: nocreate); // by default, the file is opened in ios: in mode. If the file does not exist, the operation fails.
Ofstream f ("d: 12.txt"); // by default, the file is opened
error occurs when a file exists. It is often used in combination with out.IOS: Binary = 0x80 // binary format fileFile Protection option:Filebuf: openprot; // default compatible Sharing ModeFilebuf: sh_none; // exclusive, not sharedFilebuf: sh_read; // read sharingFilebuf: sh_write; // write sharingHow to open a fileSpecify the file name and open mode when calli
, the pointer position is always at the last
Ios::trunc = 0x10,//Truncate the file length to 0 (default) before reading and writing
Ios::nocreate = 0x20,//The file does not exist and generates an error, often combined with in or app
Ios::noreplace = 0x40,//file generated error when present, common and out combined use
Ios::binary = 0x80//binary format
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.