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
3
votes
1 answer

NodeJs writeFile writes "object object" in txt file instead of actual elements of objects

function querydb(){ cursor = dbConnection.collection("logs").find(queryObj).limit(valueList[1]); /*Either decide here to foreach for file or for console OR...*/ cursor.forEach(function(item){ /*Decide here whether to write to file or…
3
votes
4 answers

Writing and Reading from a file at the same time

I've been trying to read and write from a file at the same time and I'm trying to substitute all the tabs in the content of text.txt to be turned into spaces. This is my code: int main() { FILE* filePtr = fopen("text.txt", "w+"); char c; c…
Anas Ayubi
  • 227
  • 1
  • 3
  • 9
3
votes
3 answers

Is it possible to "intercept" a 3rd party library's "WriteFile" operation

This is likely a long shot, but I thought I'd ask anyway. I'm using a document management system's API. They provide a "WriteFile" method to save a given document to disk. However, the library does not have a way to simply read a document into…
stout
  • 249
  • 1
  • 5
  • 8
3
votes
2 answers

Erlang, how can I create text file with newlines?

Somebody knows how can I append a new line in the text file in Erlang language? I want to save this list: Data = ["one", "two", "three"], into the text file with new lines: one two three I tried: write() -> Data = ["1","2","3"], Print =…
3
votes
1 answer

how to use php to write html tag to another html file?

I have two files. One is input.php, the other is output.html. Inner input.php file the code is like: loadHTMLFile($file); $elements = $doc->getElementsByTagName('head'); …
Kurt X
  • 217
  • 1
  • 6
  • 12
2
votes
2 answers

Trouble with Response.WriteFile / Response.BinaryWrite / Response.TransmitFile (ASP.NET)

I've got a simple web-page that generates a CSV file that I want the user to be able to download once its creation is complete. Here's a summary of my situation: The CSV file can be created in-memory or on disk. Doesn't matter to me. Once I'm done…
mbm29414
  • 11,558
  • 6
  • 56
  • 87
2
votes
5 answers

Write a unicode CString to a file using WriteFile API

How can I write contents of a CString instance to a file opened by CreateFile using WriteFile Win32 API function? Please note MFC is not used, and CString is used by including "atlstr.h" edit: Can just I do WriteFile(handle, cstr,…
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
2
votes
1 answer

Get Root privilege in python

I wanted to write in a file which required root privilege. Run python script as Normal User Switch to root privilege using password( password can be provided in code) Edit file which needed root privilege Back to normal user
2
votes
0 answers

Error shows up when using df.to_parquet("filename")

I want to save the data set as a parquet file, called power.parquet, and I use df.to_parquet(). But it gives me this errer "ValueError: Error converting column "Global_reactive_power" to bytes using encoding UTF8. Original error: bad…
lok6666
  • 21
  • 4
2
votes
2 answers

Write a file to network location in Linux using C#

The below program written in C# which runs fine in Windows but when it comes to running in Linux ( inside a docker container) it doesn't translate the path properly. class Program { static void Main(string[] args) { …
vkandvia
  • 85
  • 12
2
votes
2 answers

WriteFile returning error 1784

I am creating a program to populate a disk with a dummy file system. Currently, I am writing files of variable sizes using WriteFile. WriteFile(hFile, FileData, i * 1024, &dwWrote, NULL); err = GetLastError(); err returns #1784…
jscott
  • 397
  • 2
  • 5
  • 18
2
votes
2 answers

WriteFile failing depending on length of data to write?

EDIT Oddly enough, I've worked around this issue, but it's still annoying me. I worked around it by sending too-long writes, with padded zeroes; the code works but sends a few hundred unnecessary bytes. Specifically, I need to send exactly…
Sukasa
  • 1,700
  • 4
  • 22
  • 40
2
votes
2 answers

Write dictionary to text file with newline

I have a python dictionary {'A': '1', 'B': '2', 'C': '3'}. I want to write this dictionary into a file. This is how I did it; test_dict = {'A': '1', 'B': '2', 'C': '3'} f = open("dict.txt", "w") f.write(str(test_dict)) f.close() However, what I…
user3848207
  • 3,737
  • 17
  • 59
  • 104
2
votes
1 answer

How to write to and read from a file in my assets folder in a flutter app?

I am trying to write to and read from a file that is in the assets folder in a flutter app. Generally, how should it be done? I tried the following approach:- void writeToFile(String data) async { final String filename = 'colors.json'; await…
iMujtaba8488
  • 241
  • 3
  • 9
2
votes
1 answer

Writing last N bytes to file opened with FILE_FLAG_NO_BUFFERING

When writing lots of sequential data to disk I found that having an internal 4MB buffer and when opening the file for writing I specify [FILE_FLAG_NO_BUFFERING][1], so that my internal buffer is used. But that also creates a requirement to write in…
leiflundgren
  • 2,876
  • 7
  • 35
  • 53