file-io

Append XML to file without writing it from scratch? [duplicate]

 ̄綄美尐妖づ 提交于 2020-01-05 07:08:20
问题 This question already has answers here : Fastest way to add new node to end of an xml? (10 answers) Closed 2 years ago . The standard way to append an XML file in LINQ-to-XML is to read it in, modify the in-memory document, and write the whole file out from scratch. For example: XDocument doc = XDocument.Load("pathToDoc.xml"); doc.Root.Add(new XElement(namespace + "anotherChild", new XAttribute("child-id", childId))); doc.Save("pathToDoc.xml"); Or, with a FileStream : using (FileStream fs =

Append XML to file without writing it from scratch? [duplicate]

穿精又带淫゛_ 提交于 2020-01-05 07:08:13
问题 This question already has answers here : Fastest way to add new node to end of an xml? (10 answers) Closed 2 years ago . The standard way to append an XML file in LINQ-to-XML is to read it in, modify the in-memory document, and write the whole file out from scratch. For example: XDocument doc = XDocument.Load("pathToDoc.xml"); doc.Root.Add(new XElement(namespace + "anotherChild", new XAttribute("child-id", childId))); doc.Save("pathToDoc.xml"); Or, with a FileStream : using (FileStream fs =

How to read one whole line from text file using <

妖精的绣舞 提交于 2020-01-05 06:56:28
问题 I am trying to get one whole line from some text file instead of one word until it meets white space, here is source code: #include <stdio.h> void main() { int lineNum=0; char lineContent[100]; scanf("%s", &lineContent); printf("%s\n", lineContent); } And here is my text file, called test.txt, content containing 2 lines: 111 John Smith 100 98 1.2 2.5 3.6 222 Bob Smith 90 91 3.2 6.5 9.6 And I run it with following command: a.out < test.txt My output is just: 111 What I want is: 111 John Smith

makedirs error: can GAE Python create new directories (folders) or not?

烈酒焚心 提交于 2020-01-05 06:55:34
问题 I have seen a number of questions relating to writing files & creating new directories using Python and GAE, but a number of them conclude (not only on SO) by saying that Python cannot write files or create new directories. Yet these commands exist and plenty of other people seem to be writing files and opening directories no problem. I'm trying to write to .txt files and create folders and getting the following errors: Case #1: with open("aardvark.txt", "a") as myfile: myfile.write("i can't

How to find unknown number of rows and cols from input file?

一世执手 提交于 2020-01-05 06:50:17
问题 So the input file will look similar to this, it can be arbitrary..: 000001000101000 010100101010000 101010000100000 I need to be able to find how many rows and columns are in the input file before I can start reading the file into a 2d array and I don't know if this is the right way to do it: char c; fin.get(c); COLS = 0; while ( c != '\n' && c != ' ') { fin.get(c); ++COLS; } cout << "There are " << COLS << " columns in this text file" << endl; ROWS = 1; string line; while ( getline( fin,

Batch file - date variables and moving files with variable date file name from one folder to another

元气小坏坏 提交于 2020-01-05 05:48:06
问题 I need some assistance, please. I'm trying to create a batch file to move files from one folder to another. The file name will have variable yyyy-mm format plus additional data before or after the date. The batch will need to move the file to a server directory with the same mmmm-yy folder name. I've come up with the code below, but it doesn't quite work. A "Missing Operand" error is returned. The new directory is created but the files are not moving from the old folder to the new one. My

File open fails initially when trying to open a file located on a win2k8 share but eventually can succeeed

半世苍凉 提交于 2020-01-05 04:49:29
问题 Core of the problem: I receive "(0x80070002) The system cannot find the file specified" for roughly 8 to 9 seconds before it can open it successfully. In a nutshell, we have two com components. Component A calls into Component B and asks for a UNC filename to write to - the filename returned doesn't exist yet, but the path does - it then does its work, creates and populates the file, and tells Component B its done by making another com call. At that point Component B will call MoveFile to

Uploading files: FileUpload.SaveAs or manually writing FileUpload.FileBytes

别等时光非礼了梦想. 提交于 2020-01-05 04:36:29
问题 Using the FileUpload control, please explain the difference between the following two methods of uploading file: 1. Using the FileUpload.SaveAs() method: fileUploadControl.SaveAs(path) 2. Writing a byte array to disk from FileUpload.FileBytes using File.WriteAllBytes() : File.WriteAllBytes(path, fileUploadControl.FileBytes); How would these compare when uploading large files? 回答1: These both have different purposes. SaveAs lets you save as a file directly while WriteAllBytes gives you a byte

Upload image, rename it, make thumbnail and replace the original. (optimization)

两盒软妹~` 提交于 2020-01-05 03:38:07
问题 I have created these functions which I described in the question. However I think the way I did it is not the optimal way of doing it. [HttpPost] public ActionResult Create(FormCollection collection, string schooljaarparam, FlatONASAanbieder foa) { if (ModelState.IsValid) { // var r = new List<ViewDataUploadFilesResult>(); foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; //extensie nakijken. jpg,

reading a text file into a structure

守給你的承諾、 提交于 2020-01-05 03:35:54
问题 my text file is like this (the data in the file can also increase) 822 172.28.6.56 172.34.34.53 3244 5434 844 192.150.160.145 192.67.45.123 2344 234 700 192.13.56.6 192.89.95.3 4356 3566 522 172.28.6.137 172.28.6.110 2543 5245 900 255.255.255.255 244.244.244.244 2435 3245 and my structure is like this struct input_par { int key_node; char src_ip[15]; char dst_ip[15]; int src_port; int dst_port; }; i have to fill this struture from data stored in file, once it completes inputting the 5