file-handling

Force an OleDbConnection to Release a File Handle

故事扮演 提交于 2020-01-02 07:00:28
问题 Related Question My code doesn't release a file handle even after I call dispose to an initialized OleDbException. Is there a way to explicitly force the program to release a file handle? 回答1: By default, .NET database connections use pooling. Calling Close() and Dispose() just releases the connection back into the pool, it doesn't actually force it to close. Eventually it will time out of the pool, and actually be closed. After a bit of research, there seem to be two main ways to get it

Modifying XML file in-place?

北战南征 提交于 2020-01-02 05:45:17
问题 Suppose I have the following XML File: <book> <name>sometext</name> <name>sometext</name> <name>sometext</name> <name>Dometext</name> <name>sometext</name> </book> If I wanted to modify the content by changing D to s (As shown in the fourth "name" node) without having to read/write the entire file, would this be possible? 回答1: A 10 MB file is not a problem. Slurp it up. Modify the DOM. Write it back to the filesystem. 10 GB is more of a problem. In that case: Assumption : You are not changing

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

末鹿安然 提交于 2020-01-01 02:09:11
问题 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(

How do I create a file with a user-supplied name in C++? [closed]

强颜欢笑 提交于 2019-12-31 07:44:13
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago . I want the user to be able to type some text and then the computer creates a file called what ever the text was. In C++. 回答1: #include <cstdlib> int main() { return system("read FILE && touch \"$FILE\""); } Note:

Read File line by line to variable and loop

坚强是说给别人听的谎言 提交于 2019-12-30 06:52:31
问题 I have a phone.txt like: 09236235965 09236238566 09238434444 09202645965 09236284567 09236235965 ..and so on.. How can I process this data line by line in C++ and add it to a variable. string phonenum; I know I have to open the file, but after doing so, what is done to access the next line of the file? ofstream myfile; myfile.open ("phone.txt"); and also about the variable, the process will be looped, it will make the phonenum variable the current line its processing from the phone.txt. Like

python - Steganographer File Handling Error for non plain-text files

匆匆过客 提交于 2019-12-29 09:20:07
问题 I've built a Python Steganographer and am trying to add a GUI to it. After my previous question regarding reading all kinds of files in Python. Since, the steganographer can only encode bytes in image. I want to add support to directly encode a file of any extension and encoding in it. For this, I am reading the file in binary and trying to encode it. It works fine for files which basically contains plain-text UTF-8 because it can easily encode .txt and .py files. My updated code is: from PIL

mkdir() is not creating the new directory

南笙酒味 提交于 2019-12-29 07:24:33
问题 I am using Eclipse and jdk1.7. I am making a basic program using file handling, in which an output directory inside the directory is to be made. But when I run the program, the output is showing false and the directory is not made. I thought that the output was false because of the presence of a directory with the same name, but this is not the reason. So I need help. Here is my code: import java.io.File; public class P { public static void main(String[] args) { File f1 = new File ("abc");

How can I download a file from a URL and save it in Rails?

天大地大妈咪最大 提交于 2019-12-27 11:51:08
问题 I have a URL to an image which i want to save locally, so that I can use Paperclip to produce a thumbnail for my application. What's the best way to download and save the image? (I looked into ruby file handling but did not come across anything.) 回答1: Try this: require 'open-uri' open('image.png', 'wb') do |file| file << open('http://example.com/image.png').read end 回答2: An even shorter version: require 'open-uri' download = open('http://example.com/image.png') IO.copy_stream(download, '~

How can I download a file from a URL and save it in Rails?

流过昼夜 提交于 2019-12-27 11:50:12
问题 I have a URL to an image which i want to save locally, so that I can use Paperclip to produce a thumbnail for my application. What's the best way to download and save the image? (I looked into ruby file handling but did not come across anything.) 回答1: Try this: require 'open-uri' open('image.png', 'wb') do |file| file << open('http://example.com/image.png').read end 回答2: An even shorter version: require 'open-uri' download = open('http://example.com/image.png') IO.copy_stream(download, '~

How to read particular data from file using fread?

给你一囗甜甜゛ 提交于 2019-12-25 12:23:33
问题 Following code writes data of student into a file using fwrite and reads data using fread: struct record { char name[20]; int roll; float marks; }student; #include<stdio.h> void main() { int i; FILE *fp; fp=fopen("1.txt","wb"); //opening file in wb to write into file if(fp==NULL) //check if can be open { printf("\nERROR IN OPENING FILE"); exit(1); } for(i=0;i<2;i++) { printf("ENTER NAME, ROLL_ NO AND MARKS OF STUDENT\n"); scanf("%s %d %f",student.name,&student.roll,&student.marks); fwrite(