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
votes
2 answers

Write python nested dictionary items to files

I have a nested dictionary of key, value pairs structured like this: (0, {'hoovervilles': 13, 'depression.': 10, 'everyday:': 6}), (1, {'mother': 10, 'child': 9, 'daughter': 3, 'prevail': 1}), (2, {'music': 6, 'style,': 2, 'listening': 2}) For each…
Sara Lafia
  • 135
  • 1
  • 1
  • 8
-1
votes
3 answers

Get filepath to a variable immedietely after fs.writefile

I am trying to get the path of the file that I am writing as below. help me with code how to get the path from the below function. I need the file path as the return variable. I am passing a number as barcodeSourceNumber. pathToFile =…
Shiva Nara
  • 81
  • 1
  • 2
  • 10
-1
votes
1 answer

How to write line by line into a file in a loop using python?

I run into some new problems again. I'm trying to write line by line, according to a condition, into a new file from a file. I can print the lines that I need, but couldn't write it into a file. Here is what I write: import os with…
Devin Liu
  • 17
  • 3
-1
votes
1 answer

How to get a device handle to pass to WriteFile within UWP C#

I have an UWP C# application that needs to use printers that are connected via USB. Unfortunately the UWP built-in functionality for these sorts of devices (Windows.Devices.Usb namespace) has some major shortcomings. It doesn't recognize the USB…
-1
votes
1 answer

How to pass ESC/POS commands to WriteFile FileAPI method?

I have some trouble with ESC/POS commands. The code below prints well regular text, but when it comes down the ESC/POS commands the printer does nothing. I have tried many different ways how to pass on the data (see cData1 & cData2). Can anyone help…
-1
votes
1 answer

How to to check if a folder doesn't exist to create a file inside of it?

I am trying to check if folder exist if not the system create it and a JSON file will be written inside this folder. The problem is that the system create an empty folder and displays this error: None the selected file is not readble because : …
Py Dev
  • 45
  • 8
-1
votes
1 answer

Why is it saying access denied when I input the username correctly?

Hey I have wrote this code however I cannot see what is wrong with it, it is saying that the username is wrong yet if I print it, it returns exactly what i input. ea = input("Do you already have an account") if ea == "Yes" or ea == "yes": …
Clout
  • 3
  • 2
-1
votes
1 answer

How to write this json like format on a txt file using the node.js

I want this format 1 {"index": {"_id": 0}} 2 { "age_groups" : ["-KmQN3SH7_ ........100000 words in sinle line 3 {"index": {"_id": 1}} 4 { "age_groups" : ["-KmQN3SH7_ ........100000 words in sinle line 5 {"index": {"_id": 2}} 6 {…
George C.
  • 6,574
  • 12
  • 55
  • 80
-1
votes
1 answer

How to add an element at the beginning of a line in a file in Scala

I have a file, e.g., like this: // file_1.txt 10 2 3 20 5 6 30 8 9 I need to write a letter with a space before each line that meets a criterion regarding the first value / number in the line, e.g., if I give the value 20 then the file should look…
Avah
  • 227
  • 3
  • 13
-1
votes
1 answer

How to create an int file

I am trying to create a shared file, which has to be int. int f; However, when I reach if ((fstat(f, &stbuf) != 0) || (!S_ISREG(stbuf.st_mode))) It gives me an error. The file must contain a string like: abcd My guess is the following, but it…
-1
votes
2 answers

error: could not convert from 'std::string* {aka std::basic_string*}' to 'std::string {aka std::basic_string}'|

I'm trying to make a function that writes a file but i'm having issues passing a string as a parameter. void writeFile(string filename, string letters, int size) { ofstream outputfile("output.txt"); outputfile << letters; …
SaltyCode
  • 67
  • 1
  • 2
  • 11
-1
votes
1 answer

wrong detail is written on the file in c programming

I'm using switch case and have loop and if/else in the case. Even there is no error detected,i still cant figure out why would it wont display the correct type of car in the file. It is frustrating bc my due date is tomorrow. The coding is at case…
husnatasnim
  • 43
  • 1
  • 6
-1
votes
2 answers

Java Write to a Text File

I have to read a text file into the console, and then write it back in it. I was able to read the file to the console, but when I write back to it and try to read it next time, the file is empty. Can anyone tell me where I'm making mistake? Here Is…
user5517779
  • 33
  • 2
  • 10
-1
votes
1 answer

read write file Substitution_Ciphers

i am trying to read write from a file but i am always getting a error while either reading or writing to the file. when option -d is used, the input file will contain the ciphertext and the output file will contain the original plaintext, and the…
Abdulla
  • 39
  • 1
  • 2
  • 6
-1
votes
1 answer

Java: read 2 files and compare line by line

I'm trying to compare two files line by line. Let's say for example: File1 a,b,c,d,12 e,f,g,h,20 h,g,t,y,30 File2 f,g,h,j,30 e,h,j,f,50 a,b,c,d,60 e,f,g,h,70 I want my output to be like: a,b,c,d,12,50 e,f,g,h,20,70 I've written this code: while…
Ravi Krishna
  • 67
  • 1
  • 9