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

write files/cookies with codeigniter

How should I go about with writing files that should not be accessible to the public? First how can I write to file outside of the CI root folder? Second to be able to write file, I need to set the file permission to 777, which then would become…
TurtleTread
  • 1,297
  • 2
  • 12
  • 23
0
votes
2 answers

Simple Mailslot program not working?

Using the client and server examples found here: http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedmailslot14.html Compiling them with VS2008, running the server and then "client Myslot" I keep getting "WriteFail…
Shawn
  • 2,356
  • 6
  • 48
  • 82
0
votes
3 answers

Why does .NET not clear errors internally?

I am running the following scenerio: SafeFileHandle handle = Win32API.CreateFile((deviceName + "\\" + pipeName), DesiredAccess.GENERIC_WRITE | DesiredAccess.GENERIC_READ, …
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
0
votes
4 answers

Android: write to file OnDestroy()

Here's my current situation: Eclipse Win7 Samsung SII (for testing) I am writing an Application that will read from a file stored privately on the device when it starts, and then, i want to write to that same file (overwrite basically) when the…
MaxOvrdrv
  • 1,780
  • 17
  • 32
0
votes
1 answer

Write to a txt file using windows API

I am trying to write some lines to a a txt file through an ATL application. Below is the fragment of code I use: HANDLE hFile = CreateFile(ofn.lpstrFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, …
arjacsoh
  • 8,932
  • 28
  • 106
  • 166
0
votes
3 answers

Couldn't write integer file into a file in java

I am trying to save the output of calculated data rate in a file. The data rate is of integer type, and I am not able to save it in a file, and I get the following error: Exception in thread "main" java.io.IOException: Write error at…
Iman Dz
  • 29
  • 1
  • 2
  • 9
0
votes
1 answer

cannot update a field of a record in a relative file, C++

After adding records in the relative file, I am trying to update one field (the balance) of a given record(client) that the user provide the account number. The update happens in the file, but it is not properly done. The output shows that the…
T4000
  • 231
  • 1
  • 7
  • 24
0
votes
1 answer

WriteFile to stdout fails after freopen

I have wrote the following code: int fd = _dup(fileno(stdout)); FILE* tmp = freopen("tmp","w+",stdout); HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); if (out == INVALID_HANDLE_VALUE){ //error } else if (out == NULL) { //error } else { …
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
-1
votes
1 answer

Write String to Mapped File With Windows Api

I'm trying to write a string to a mapped file with c and visual studio. ( pFile = (char *) MapViewOfFile(hMMap,FILE_MAP_ALL_ACCESS,0,0,0)) start = pFile; while(pFile < start + 750){ *(pFile++) = ' '; *(pFile++) = 'D'; …
Ömer Faruk AK
  • 2,409
  • 5
  • 26
  • 47
-1
votes
1 answer

Append at the beginning of the file

I am using winapi's CreateFile() and WriteFile() functions to open the file in append mode and write into the file. When i use FILE_APPEND_DATA flag, and then write into the file, it append the new item at the end of the file, but i want to append…
Vinay Khatri
  • 312
  • 1
  • 8
-1
votes
1 answer

ERROR: Module not found: Can't resolve 'node:fs' in 'D:\Codes\ToDo\todo\node_modules\write-json-file'

I am facing with this error for days: tried anything written on the internet, but still persisting the error--> ./node_modules/write-json-file/index.js Module not found: Can't resolve 'node:fs' in…
info_deniz
  • 33
  • 4
-1
votes
1 answer

Jump to next line after writing a word in a file

user_bw = message.content; fs.writeFile("badwordlog.txt", user_bw, (err) => { if (err) console.log(err); else { console.log("badwordlog edited !"); } }); I need to store all the badwords in a file . How to print the next word…
Jane
  • 1
  • 1
-1
votes
1 answer

Can't open a write file

I can't open the file as a write file. script = argv filename = argv print(f"We're going to erase {filename}. ") print("If you don't want that, hit CTRL-C (^C). ") print("If you do want that, hit RETURN. ") input("?") print("Opening the…
egegk
  • 1
  • 3
-1
votes
1 answer

Can I write a file on the webhost's computer with Javascript?

I am trying to make an online game and I am using JavaScript on repl.it and I want to save the player's high score when they lose. I have a file called high_scores.txt that is in the same directory as my script.js file, and I want to write the…
Shark Coding
  • 143
  • 1
  • 10
-1
votes
2 answers

What does "process.argv[2]" mean in this Node fs write function?

Just started learning Node and I'm reviewing exercises from class today. Can't remember what the "process.argv[2]" refers to when writing a new file using fs. I'm thinking [0] would refer to "node", and [1] would refer to the name of the file that…
rgrzdv
  • 1
  • 1