Questions tagged [writefile]

For questions about writing to a file. It could be referencing appending data, rewriting all existing content, or other related uses of functions that programmatically edit files. It is not limited to a certain language.

This tag is most often used when someone wants to add/insert content to a file programmatically. One example is in the Node JS function fs.writeFile, which is used to create files and write to them.

This is an example script which shows the usage of fs.writeFile to write a string to message.txt.

// Node JS

const fs = require('fs');
const data = new Uint8Array(Buffer.from('Hello Node.js'));

fs.writeFile('message.txt', data, (err) => {
  if (err) throw err;
  console.log('The file has been saved!');
});

Make sure to pair this tag with a language tag as is generally not specific enough to describe a complete question.

494 questions
6
votes
1 answer

Using Pipes to read and write binary data in Haskell

I am trying to read and write very many ints in constant memory. I have figured out how to write the ints to memory but have not figured out how to read them back. import Control.Lens (zoom) import System.IO (IOMode(..), withFile) import…
Justin Raymond
  • 3,413
  • 2
  • 19
  • 28
6
votes
6 answers

Unable to write file in C++

I'm trying to to the most basic of things .... write a file in C++, but the file is not being written. I don't get any errors either. Maybe I'm missing something obvious ... or what? I thought there was something wrong with my code, but I also…
Thorgeir
  • 3,960
  • 3
  • 24
  • 20
5
votes
1 answer

Create folders dynamically and write csv files to that folders

I would like to read several input files from a folder, perform some transformations,create folders on the fly and write the csv to corresponding folders. The point here is I have the input path which is like "Input…
The Great
  • 7,215
  • 7
  • 40
  • 128
5
votes
3 answers

Best way to write rows of a numpy array to file inside, NOT after, a loop?

I'm new here and to python in general, so please forgive any formatting issues and whatever else. I'm a physicist and I have a parametric model, where I want to iterate over one or more of the model's parameter values (possibly in an MCMC setting).…
5
votes
2 answers

Replace a line in txt file using JavaScript

I am trying to simply replace a line in a text file using JavaScript. The idea is: var oldLine = 'This is the old line'; var newLine = 'This new line replaces the old line'; Now i want to specify a file, find the oldLine and replace it with the…
Wibo Kuipers
  • 83
  • 1
  • 2
  • 11
5
votes
1 answer

WriteFile hangs the application when using WaitCommEvent

I am encoutering a issues with win32 programming doing a serial port communication using a event-driven approach. I have my communication handle created as: hComm = CreateFile(lpszCommName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,…
5
votes
1 answer

Writing to a .txt file before node.js exits

I'd like my server to save some essential data when node exits and load them next time. I tried what the answer of this question suggested, but the server seems to close before it is able to write to the file. This is the exact code I am…
user3262713
  • 369
  • 8
  • 20
5
votes
3 answers

Read data from a text file and create an object

I need some help: I'm making a Supermarket simulation on Java, but I've got one problem, I have a text file (Stock.txt) where I have all the supermarket stock on it for example: 0-Bakery-Chocolate Cake-$12.5-250 1-Meat-Premium…
DkRckr12
  • 183
  • 1
  • 1
  • 3
5
votes
5 answers

Serial port WriteFile() freeze

I have a simple application, which should send a single byte to a serial port once a minute. But sometimes, from some strange reason, it freezes somewhere in the WriteFile() function. Both sw and hw flow controls are turned off. I've googled some…
Ladislav
5
votes
4 answers

WriteFile vs TransmitFile for large files that need to be deleted from the server after transfer

I have to trigger user downloads of large files to a webbrowser, where I create the file to transfer on the server, then delete it immediately afterwards. I've found enough examples to see that I should probably use Response.TransmitFile or…
tbischel
  • 6,337
  • 11
  • 51
  • 73
4
votes
1 answer

fs.writeFile (node) adds information on an already existing file instead of replacing this

I made a code to write a file using fs and node-cron to run this every x minutes. I get the data the first time, but in the next job I get the data added again in the file and the old one too, I wan to create a new file and replace the old one (and…
4
votes
2 answers

How to solve error (OS Error: No such file or directory, errno = 2) reading file in flutter

I recently started programming mobile applications with flutter. I have a problem with reading a file. In practice, while the app is running I write a string to a text file (and I can also read it correctly). My need is to read from this file every…
Viir7
  • 41
  • 1
  • 1
  • 2
4
votes
2 answers

Writing synchronously to a file opened with FILE_FLAG_OVERLAPPED

I have opened a file using HANDLE handle= CreateFileW( fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); The file handle is then used for asynchronous read…
Etan
  • 17,014
  • 17
  • 89
  • 148
4
votes
0 answers

how to write to a file with multithreading in php

In А.php is executed foreach($allUsers as $cnt=>$arUser){ shell_exec("nohup php /B.php $arUser > TestFile.log & echo $!"); } in script B.php I write log file_put_contents('Log.log', " action \r\n", FILE_APPEND | LOCK_EX); But part of the…
4
votes
2 answers

Write text to file in C# with 513 space characters

Here is a code that writes the string to a file System.IO.File.WriteAllText("test.txt", "P …
amyn
  • 922
  • 11
  • 24
1
2
3
32 33