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
1
vote
1 answer

Python, keyword searching code in a large .log file

im new to python and im building a keyword searching program that´s supposed to find every word that´s the same in a larg .log file (for now, word "Time stamp") and store the values in seperate .log file. This is the code i have written and my…
Filip Kaiser
  • 37
  • 1
  • 8
1
vote
0 answers

nodejs: compare function generated JSON data to JSON file

I have a function that scans a directory and creates a JSON file with the audio files metadata. I want it to check if the file already exists and only overwrite if there is any diference between the file that was created from the last time the…
medicengonzo
  • 479
  • 1
  • 7
  • 23
1
vote
2 answers

python read value from file and change it and write back to file

i am reading a value from a file and then adding up with another and then writing back to the same file. total = 0 initial = 10 with open('file.txt', 'rb') as inp, open('file.txt', 'wb') as outp: content = inp.read() try: total =…
jacky
  • 524
  • 1
  • 5
  • 15
1
vote
1 answer

How store JSON response and save into JSON file

I am using SwiftyJSON to read the API response. I want to store the JSON response locally in user device by creating JSON file for offline. My function which returns create JSON: Alamofire.request(HostURL) .responseJSON { response in …
Nick
  • 1,127
  • 2
  • 15
  • 40
1
vote
2 answers

MATLAB: export scalars within for loop to text file

I have a large number of text files that I have to read, find the max value for a certain column, and the corresponding time. The for loop for finding these values works fine, but my problem is writing a text file that shows the three variables I…
1
vote
0 answers

Sdfatlib(Arduino) SD card not recieving data

I am at a loss here, and I would really like some help if it can be provided. I have searched the website for similar problems, but I've not found anything similar enough to fulfill my query. I've been trying to utilise the sdfatlib library to have…
1
vote
1 answer

Read & write txt file error - 'str' object has no attribute 'name', polish dialectical chars in path error

I use Python 2.7 on Win 7 Pro SP1. I try code: import os path = "E:/data/keyword" os.chdir(path) files = os.listdir(path) query = "{keyword} AND NOT(" result = open("query.txt", "w") for file in files: if file.endswith(".txt"): file_path…
1
vote
2 answers

saving an opencv mat to txt file as hex values without separators

I'm trying to save an OpenCV mat containing image pixels to a txt file (that will be imported to a VHDL testbench afterwards for further processing). I need the file to contain only pixel values without any other information and I need it to be in…
R.T
  • 25
  • 6
1
vote
2 answers

[MATLAB]: Writing data in Excel return always 1

I want to write an array of increasing integer from Matlab to an Excel file. So I wrote the following code : T=linspace(1,172800,172800); xlswrite('example.xlsx',T,'A1:A172800'); The result is an excel sheet with the first column (from row1 to…
Bernheart
  • 607
  • 1
  • 8
  • 17
1
vote
1 answer

Anonymous pipes: ReadFile in parent process keeps on waiting when the child process is killed

I have a program in which a parent process spawns off a child process and then communicates with it. Parent process is a VB application and the child process is a C# console application. Parent Process (Removed error handling for now): Private…
ykhandel
  • 29
  • 3
1
vote
1 answer

Deviare2 hook WriteFile API twice for only one write

Deviare2 is a professional API Hook Library on MS Windows. It's easy use and powerful. But when I want to hook WriteFile using a C# dummy writer ,I found it hooked WriteFile twice. I try to use API Monitor to hook dummy writer, I found API Monitor…
1
vote
1 answer

Node writeFileSync encoding options for images

I'm using fs.writeFileSync(file, data[, options]) to save a file returned from http.get(options[, callback]) This works fine for text files but images, pdfs etc end up being corrupted. From the searching around that I've done, it's apparently…
Ryuu
  • 596
  • 1
  • 5
  • 26
1
vote
1 answer

"Writefile" for RS232 communication using MFC hangs forever, but

I am maintaining a MFC program which can send data from computer A to computer B through RS232. Sometimes it transmits data smoothly, but sometimes it hangs forever. There are two threads sending the same data to a com port in sequence. The first…
ohnotme
  • 23
  • 3
1
vote
1 answer

Not able to copy pdf file from raw to run time created sdcard folder

i use this code to create a folder in sdcard n it is created sucesfully private void CreateFolder() { File folder = new File(Environment.getExternalStorageDirectory() + File.separator + "Books"); boolean success = true; if…
shukar
  • 19
  • 2
1
vote
1 answer

Javascript How to Create and Write to Local txt file

Need expert ideas how to Create and Write to .txt file on JavaScript. I am using below code it works fine with IE but not on Chrome with error as "ActiveXObject" undefined. "ActiveXObject" related to IE specific not supported on Chrome. var myObject…
Sunil
  • 11
  • 2