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

Upload problem in server "undefined" because I wanted the name of the file

Hi everyone so I just wanted to know where I could find the file name in my object. I did a console.log to find the property but I was a little bit lost. I tried to do ${data.name} but it says undefined. Anyone know where can I find it in my request…
MrBigboka
  • 409
  • 1
  • 4
  • 12
1
vote
1 answer

How to send data correctly using writeFile with Cypress

I'm practicing and was trying to write in a file, all names and links of 'cars' from amazon. The following code is working but will only write one line in the txt file. How can I write the complete list? Maybe as an object? Is there a better way to…
Vicko
  • 234
  • 4
  • 17
1
vote
1 answer

ExpressJS - how to writeFile passed from the front-end file upload FileReader

I found a many posts around this topic but after much tweaking still can't get the file upload to work correctly. I have a form with a PDF file upload in React, something like this: this.handleFileUpload(e)} required …
geochanto
  • 972
  • 2
  • 13
  • 45
1
vote
1 answer

Reading the dynamic bitset written data from file cannot read the correct data

So I have a vector which has three numbers. 65, 66, and 67. I am converting these numbers from int to binary and appending them in a string. the string becomes 100000110000101000011 (65, 66, 67 respectively). I am writing this data into a file…
1
vote
5 answers

Suggestion about storing values in file in Java?

I have a program where i generate a huge matrix and once it is calculated, i have to reuse it at later times. For that reason, i want to cache it to the local hard disk so that i can read it at later times. I am using it simply by writing data to…
Johnydep
  • 6,027
  • 20
  • 57
  • 74
1
vote
0 answers

File Busy when writing multiple time quickly in NodeJS

In NodeJS, I am logging every every API request and would get the log through another API request . But I do not want to use MONGODB or any such database. I am currently writing to file each API request in JSON format. But now API requests are much…
Bhavya Gupta
  • 186
  • 2
  • 12
1
vote
1 answer

Saving file in specified directory Node.js

I want to save an image using fs.writeFile, but I'm not able to do this. The path in which i want to do this: C:\Users\poz\lotos\images\1232133123@gmail.com My code: var d = new Date(); var n = d.getTime() + ".jpeg"; var dir =…
Casper222
  • 101
  • 2
  • 9
1
vote
0 answers

How to use Writefile() command to save a json file that has 'unicode' encoding

When I run my JS file, I use the Writefile() command to create a Json file in the file explorer. This file saves with ANSI encoding. I am wondering if there is a way to run the writefile() command to save the file with 'Unicode' encoding. Any help…
1
vote
1 answer

node fs.fsync (when to use?)

I want to safely write a file and I wan't to understand the proper use/place for fsync. https://linux.die.net/man/2/fsync After reading ^ that, I am puzzled as to where to effectively use it. Question, do…
Ben Muircroft
  • 2,936
  • 8
  • 39
  • 66
1
vote
3 answers

How to write binary file from hex string in Windows command prompt

I want to make binary executable file from hex string in windows cmd. I used "echo" cmd command but it is written in normal string, not binary format. So output exe file could not be executed. input:…
monkey king
  • 23
  • 1
  • 5
1
vote
1 answer

What error could be called in the file system Node.js module?

I am simply wondering what error could be called in the writeFile() method from the fs module in Node.js. Here is an example: const fs = require("fs"); fs.writeFile("hello-world.txt", "Hello World!", (error) => { if (error) { //…
MisterHazza
  • 188
  • 1
  • 10
1
vote
0 answers

Write frame into MP4 format using opencv2 and c++

I am trying to write the frame into my local machine in mp4 format. The frame is read from an existing mp4 file. After running the following code, I was able to see the VideoOutput.mp4 file, but it is corrupted for some reason. Anyone knows why? …
superninja
  • 3,114
  • 7
  • 30
  • 63
1
vote
2 answers

How to Clear variables from JTextFields without closing whole program?

I have created a text file in which to store some variables which are taken from text fields. But in order to submit new variables to this text file, I need to close my program and reopen it. The dispose(); command closes the JFrame taking me to my…
Darren Burgess
  • 4,200
  • 6
  • 27
  • 43
1
vote
1 answer

C++ Network IO, File handling and network failures

I would like to create a new file on a different machine in the network and write to it. I use CreateFile and WriteFile MSDN functions to create and write to the file. The problem here is writes to the network disk are inconsistent during network…
Britto
  • 501
  • 1
  • 9
  • 22
1
vote
2 answers

Write a file into specific folder in node js?

Would like to write data into specific folder using writefile in node js. I have seen couple of questions in stackoverflow regarding this but none of them worked for me . For example : fs.writeFile('./niktoResults/result.txt', 'This is my text',…
Jakka rohith
  • 475
  • 2
  • 7
  • 15