file-handling

How can I use file_put_contents() with FILE_APPEND | LOCK_EX safety?

丶灬走出姿态 提交于 2019-12-04 02:54:10
I'm using: file_put_contents("peopleList.txt", $person, FILE_APPEND | LOCK_EX); to write to the end of a file and to make sure no one else (or script) is also writing to the same file at the same time. The PHP manual says it will return a falsy value if unsuccessful. If it cannot obtain a lock on the file, will it fail or keep trying until it can? If it does fail when no lock can be obtained, what would be the best way to go about ensuring the data is written? Perhaps looping the function in a while loop until it does not return false (cringe) or simply providing the user (website visiter)

Giving path of a file in C#

浪子不回头ぞ 提交于 2019-12-04 02:18:06
问题 I want to open a xxx.txt file kept on desktop of my Computer but the program gives an error Parser error unrecognized escape sequence '\D' . I am trying to give the path of the file as "C:\Documents and Settings\user\Desktop\xxx.txt" . Am i giving the path in a right way or is there any other way to give it 回答1: \ is an escape character in C# strings. It is used for special characters, such as line break ( \n ). To write a literal \ you have to quote with another \ : string myFileName = "C:\

How to copy file from one directory to other in azure through java service?

谁说胖子不能爱 提交于 2019-12-04 02:00:24
问题 I am creating application to copy file from one directory to another. jSON input is : { "accountName" : "name", "accountKey" : "key", "source" : "directory1/directory2/directory3/directory4", "destination" : "directory1/directory2", "fileToCopy" : "1" } Directory 4 is under directory 3, 3 is under 2 and 2 is under 1. Want to copy file named as "1" from directory 4 to directory 2. My java code is : @Override public JSONObject copyFile(JSONObject jsonInput) throws IOException,

C Win32: save .bmp image from HBITMAP

感情迁移 提交于 2019-12-04 01:37:22
I am working with a framegrabber and need to get the images from computer memory and save them on an image file. after trying for couple of days I end up with the following 2 functions, which creates a file and windows OS is able to run the .bmp file, but the bitmap file is black (the image size is 900KB , 640*480). does any body has any idea why, the picture is in black? here are the two functions : LPSTR CreateBMP( HWND hAppWnd, int nImageType ) { void * pWinGBits = NULL; int i; Z_BITMAPINFO zWinGHeader; // bitmapinfo for cerating the DIB // create DC for bitmap. hDCBits = CreateCompatibleDC

Exception Handling and Opening a File?

社会主义新天地 提交于 2019-12-03 19:11:35
问题 Is it possible to use exceptions with file opening as an alternative to using .is_open() ? For example: ifstream input; try{ input.open("somefile.txt"); }catch(someException){ //Catch exception here } If so, what type is someException ? 回答1: http://en.cppreference.com/w/cpp/io/basic_ios/exceptions Also read this answer 11085151 which references this article // ios::exceptions #include <iostream> #include <fstream> using namespace std; void do_something_with(char ch) {} // Process the

How feof() works in C

ぐ巨炮叔叔 提交于 2019-12-03 17:57:37
问题 Does feof() checks for eof for the current position of filepointer or checks for the position next to current filepointer? Thanks for your help ! 回答1: Every FILE stream has an internal flag that indicates whether the caller has tried to read past the end of the file already. feof returns that flag. The flag does not indicate whether the current file position is as the end of the file, only whether a previous read has tried to read past the end of the file. As an example, let's walk through

How to extract data from a line which has fields separated by '|' character in C++?

為{幸葍}努か 提交于 2019-12-03 09:04:22
I have data in the following format in a text file. Filename - empdata.txt Note that there are no blank space between the lines. Sl|EmployeeID|Name|Department|Band|Location 1|327427|Brock Mcneil|Research and Development|U2|Pune 2|310456|Acton Golden|Advertising|P3|Hyderabad 3|305540|Hollee Camacho|Payroll|U3|Bangalore 4|218801|Simone Myers|Public Relations|U3|Pune 5|144051|Eaton Benson|Advertising|P1|Chennai I have a class like this class empdata { public: int sl,empNO; char name[20],department[20],band[3],location[20]; }; I created an array of objects of class empdata. How to read the data

What is ios::in|ios::out?

回眸只為那壹抹淺笑 提交于 2019-12-03 05:38:35
I was reading some project code and I found this,here MembersOfLibrary() is a constructor of class MenberOfLibrary class MembersOfLibrary { public: MembersOfLibrary(); ~MembersOfLibrary() {} void addMember(); void removeMember(); unsigned int searchMember(unsigned int MembershipNo); void searchMember(unsigned char * name); void displayMember(); private: Members libMembers; }; MembersOfLibrary::MembersOfLibrary() { fstream memberData; memberData.open("member.txt", ios::in|ios::out); if(!memberData) { cout<<"\nNot able to create a file. MAJOR OS ERROR!! \n"; } memberData.close(); } I m not able

Exception Handling and Opening a File?

吃可爱长大的小学妹 提交于 2019-12-03 02:03:13
Is it possible to use exceptions with file opening as an alternative to using .is_open() ? For example: ifstream input; try{ input.open("somefile.txt"); }catch(someException){ //Catch exception here } If so, what type is someException ? http://en.cppreference.com/w/cpp/io/basic_ios/exceptions Also read this answer 11085151 which references this article // ios::exceptions #include <iostream> #include <fstream> using namespace std; void do_something_with(char ch) {} // Process the character int main () { ifstream file; file.exceptions ( ifstream::badbit ); // No need to check failbit try { file

Redirect output of a function that converts pdf to txt files to a new folder in python

丶灬走出姿态 提交于 2019-12-02 19:04:20
问题 I am using python 3. My code uses pdfminer to convert pdf to text. I want to get the output of these files in a new folder. Currently it's coming in the existing folder from which it does the conversion to .txt using pdfminer. How do I redirect the output to a different folder. I want the output in a folder called "D:\extracted_text" Code till now: from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import TextConverter from pdfminer.layout import