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

In Java when writing an array to file, only the last line is written

I am trying to write an array to a file using a loop, but every time I open the text file it only shows the last line. If I write the array directly with a toString it has the extra spaces and array characters I don't want. Here is my code for…
0
votes
1 answer

Java: reading file and then writting data on a text file

How to read a file and then write the data into a .txt file in java? Below is my code. I am reading a file with extension .ivt. There are some tables in .ivt and reset is a text that describes what data is all about. I have to read the text stored…
Deep
  • 108
  • 1
  • 1
  • 12
0
votes
1 answer

give UTC time as name of output file

I am writing a code that records some data . I want to record output and automatically give UTC time as name of output file .waiting for idea. Code: import datetime for message in range(0,10): utc_datetime = datetime.datetime.utcnow() print…
kian
  • 87
  • 1
  • 11
0
votes
0 answers

Writefile method error serial port

I'm trying to write serial port com 1: (to atmega8 MCU) using EscapeCommFunction Create file method, write file DCB dcb = new DCB(); [DllImport("kernel32.dll")] static extern bool SetCommState(IntPtr hFile, [In] ref DCB lpDCB); …
F Peter
  • 1
  • 1
0
votes
1 answer

Can't write text into .properties file with FileOutputStream on android

This is a part of the code I have in my SettingsActivity.java file: public class SettingsActivity extends Activity { Thread refresh = new Thread() { @Override public void run() { while…
Tom Lenc
  • 765
  • 1
  • 17
  • 41
0
votes
2 answers

Python append json to json file in a while loop

I'm trying to get all users information from GitHub API using Python Requests library. Here is my code: import requests import json url = 'https://api.github.com/users' token = "my_token" headers = {'Authorization': 'token %s' % token} r =…
Shengjie Zhang
  • 245
  • 4
  • 12
0
votes
2 answers

Don't write text into my txt file

With this code I want to read one text file, put all elements into a arraylist and replace the file with the the arraylist contain. But this code don't write into file and I don't know why... public void delete(String lineToDelete, String nameFile)…
cavaler12345
  • 367
  • 1
  • 5
  • 15
0
votes
1 answer

Create/update file(s) post dependency install, with Yeoman generator

I would like to create/update file(s) after the dependencies have been installed, when the generator(generator-custom) has been executed. $ yo custom Any pointer would be very helpful. For example, I am trying to update the devDependencies section…
Sarbbottam
  • 5,410
  • 4
  • 30
  • 41
0
votes
1 answer

WriteFile fails with error 87 (the parameter is incorrect) but works fine when debugging in Visual Studio

I create a file: m_fileHandle = CreateFileA( m_pszFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, …
LV3
  • 1
  • 1
  • 3
0
votes
1 answer

Small/annoying error- To do with Reading/Writing/Analyzing text file

So the program I'm writing reads a 3 different text files. One text file contains names, the other two contains marks. Now I have done everything correctly but there is one extra thing I want to add but I have no luck getting it right. So right now…
bob9123
  • 725
  • 1
  • 9
  • 31
0
votes
1 answer

Write folder name and their sizes in a file using Ant

I need some help with Ant. I want to create a file using Ant, which to contain some names and the size in kb of some folders and also to contain other kind of data(not size) but with the same pattern. Something like this: build.date=April 01,…
raulx222
  • 137
  • 1
  • 12
0
votes
1 answer

Assembly - Why I get the wrong character in my newly created file?

I am learning assembly and write the following: Section .text global _start _start: jmp short GoToFilename open: pop esi ; esi gets address of the filename xor eax,…
user3097712
  • 1,565
  • 6
  • 27
  • 49
0
votes
1 answer

Writing strings to a file in Java and reading them back

I have a set of strings (String objects) in Java and would like to write them to a file so that I can later retrieve them. I understand that Java uses UTF-16 to store strings internally. I am worried that I might muck something up due to formatting…
DustByte
  • 651
  • 6
  • 16
0
votes
2 answers

Why does WriteFile not run more than once?

Here's my code in which I've got on an infinite loop (to my knowledge) while(true) { DWORD TitleID = XamGetCurrentTitleId(); std::ostringstream titleMessageSS; titleMessageSS << "Here's the current title we're on : " << TitleID <<…
Curtis
  • 2,646
  • 6
  • 29
  • 53
0
votes
3 answers

Looking for a way to speed up the write to file portion of my Python code

I have a simple code that reads in a data file ~2Gb, extracts the columns of data that I need and then writes that data as columns to another file for later processing. I ran the code last night and it took close to nine hours to complete. I ran the…
Stripers247
  • 2,265
  • 11
  • 38
  • 40