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

Universal Windows Platform (UWP) write image to disk sectors

There are alot of examples of writing files to disk using UWP apis but is it possible to write an image file (.img) to disk using UWP apis + c# much in the same way win32DiskImager does?
Steve Fitzsimons
  • 3,754
  • 7
  • 27
  • 66
0
votes
1 answer

How to make space between every two pixels in a pbm file(ASCII mode)

I have a test.pbm file in ASCII mode containing the code as follows: P1 # Comment 9 9 000000000 011000000 011000000 011000000 011000000 011000010 011111110 011111110 000000000 I want to make a new file "newFile.pbm" which will contain space…
Primo
  • 19
  • 5
0
votes
2 answers

how to write array obj into file with nodejs

I'm trying with this code below, I can write file on server and the file has content but, when I download the file, it's blank. var file = fs.createWriteStream('./tmp/text.txt'); file.on('error', function(err) { console.log(err)…
beginerdeveloper
  • 785
  • 4
  • 17
  • 43
0
votes
1 answer

How to handle different file types in Node.js

I'm trying to upload and download files to SharePoint server using sp-request library for Node.js and SHAREPOINT REST API I am able to handle text files but when it comes to other types of files (images, docx ...) they always end up corrupted. So…
Ali
  • 115
  • 1
  • 10
0
votes
1 answer

Codeigniter: write_file() returns false

public function ExportCSV() { // THIS PART IS WORKING $this->load->dbutil(); $this->load->helper('file'); $delimiter = ','; $newline = "\n"; $enclosure = '"'; $filename = "tamp.csv"; $query = "SELECT politician.id,…
user7118406
0
votes
0 answers

writeFileSync producing 0 bytes file - random

A call to writeFileSync is producing a 0 bytes file at random. The aim is to write a json to a file, then re-write it every time the json changes. And also load the json on startup. But the file keeps becoming 0 bytes long, most of the time it…
eddyparkinson
  • 3,680
  • 4
  • 26
  • 52
0
votes
1 answer

How to sector align data in a buffer (win32file.FILE_FLAG_NO_BUFFERING)

Consider this program: import win32file src_file = win32file.CreateFile( r'C:\test.rar', win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, win32file.FILE_FLAG_NO_BUFFERING, None ) dst_file =…
Jexus
  • 1
  • 2
0
votes
0 answers

vertx writefile is not working

Hey am running this code and in log it's showing File written but actually it's not writing anything while in reading operation it's reading data and showing in log. Writefile,copyfile etc are not working.…
Gajender Singh
  • 1,285
  • 14
  • 13
0
votes
0 answers

How do I convert std::string to char Whatever[]?

I'm trying to convert a simple std::string to char Whatever[] Here is what I want to do: Download bin2hex (file content, with \x in front) from my server to a string, convert this string to a char Whatever[] and finally write the hex to a binary…
TheCodingBook
  • 21
  • 1
  • 7
0
votes
1 answer

how to efficiently maintain one file with max size limit but appending new to end of the file

in an Android app, need to write some data to a file. And the file cannot over the max size. If it reaches the max size it should remove top/old data and append new data to the file (like rolling up). It could be done by read in the file and remove…
lannyf
  • 9,865
  • 12
  • 70
  • 152
0
votes
2 answers

Node save filereader base64 svg upload with fs

I try to save images uploaded from the client, my code works nicely with png's and jpg's but not with svg's. What is the best way? Client side:
Dennis
  • 397
  • 1
  • 5
  • 16
0
votes
2 answers

Cannot save a string to external file on Android

Can't write my string to file on external storage. I have write and read external storage permissions in Manifest. Also added this one from previous similar questions.…
Zhangali Bidaibekov
  • 591
  • 1
  • 7
  • 13
0
votes
1 answer

write on file from serial in python in windows

I trying to have a very simple script to read data from serial port and write it on a txt file. My data are always the same and for example look like this : '4\r\n' import serial import time ser = serial.Serial('COM5', 9600, timeout=0) while 1: …
Dadep
  • 2,796
  • 5
  • 27
  • 40
0
votes
2 answers

TypeError: Unsupported only when writing to file not when printing

I've written some code (below) which worked fine until i added a statement to write it to a file. The error i get is TypeError: unsupported operand type(s) for %: 'NoneType' and 'float' which occurs on line 43. What is confusing me is the fact that…
ImNewToThis
  • 143
  • 1
  • 15
0
votes
1 answer

Node.js: strange symbol "^@" using fs.writeFile

I've built and run Node.js on emmbed linux-os with MIPS 24K Little Endian CPU. Node.js version is v0.12.0. Everything works fine except when I use fs.writeFile, example code: var fs = require('fs'); fs.writeFile("/tmp/test.txt","hello…
Sunson
  • 88
  • 1
  • 8