This tag refers to the process of writing text or data to a file.
Questions tagged [file-writing]
932 questions
6
votes
1 answer
python multiprocessing writing to shared file
When writing to an open file that I have shared via passing it to a worker function that is implemented using multiprocessing, the files contents are not written properly. Instead '^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^'…

ccdpowell
- 629
- 5
- 14
- 22
5
votes
4 answers
How to I use a class property/variable as a print filehandle in Perl?
I want to do the same thing as
open MYFILE, ">", "data.txt";
print MYFILE "Bob\n";
but instead in class variable like
sub _init_tmp_db
{
my ($self) = @_;
open $$self{tmp_db_fh}, ">", "data.txt";
print $$self{tmp_db_fh} "Bob\n";
}
It…

Jessada Thutkawkorapin
- 1,336
- 3
- 16
- 32
5
votes
6 answers
Writing a "\n" in a text file
I'm trying to write a string \n in a text file. But the result in the text file is a newline. I know that the \n represents a newline. But in my case, I really need to see the String \n, not the newline. How can I solve this?

DFE
- 51
- 1
- 1
- 2
5
votes
2 answers
How to delete the contents of a file before writing to it?
I wrote a bot that performs some network queries once every so often and dumps the latest state into a file stored on disk. This is my code:
let log_file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
…

Paul Razvan Berg
- 16,949
- 9
- 76
- 114
5
votes
2 answers
Writing tensor to a file in a visually readable manner
In pytorch, I want to write a tensor to a file and visually read the file contents. For example, consider T = torch.tensor([3,4,5,6]). I want to write the tensor T to a file, say file_T.txt, and want to visually read the contents of the file_T.txt,…

Kiran
- 87
- 1
- 1
- 5
5
votes
1 answer
What is the best way to call N concurrent functions periodically in Go?
I've been struggling with a problem for the past day or so in figuring out the best way to create N concurrent functions which are called periodically at the same interval in Go. I want to be able to specify an arbitrary number of functions, have…

Nate Mela
- 53
- 3
5
votes
2 answers
Python codec error during file write with UTF-8 string
I'm working on a Python 3 Tkinter app (OS is Windows 10) whose overall functionality includes the following details:
Reading a number of text files which may contain data in ascii, cp1252, utf-8, or any other encoding
Showing the contents of any of…

JDM
- 1,709
- 3
- 25
- 48
5
votes
3 answers
How to accelerate C++ writing speed to the speed tested by CrystalDiskMark?
Now I get about 3.6GB data per second in memory, and I need to write them on my SSD continuously. I used CrystalDiskMark to test the writing speed of my SSD, it is almost 6GB per second, so I had thought this work should not be that hard.

Chuang Men
- 371
- 3
- 10
5
votes
4 answers
How do I read and append to a text file in one pass?
I want to check if a string is inside a text file and then append that string if it's not there.
I know I can probably do that by creating two separate with methods, one for reading and another for appending, but is it possible to read and append…

multigoodverse
- 7,638
- 19
- 64
- 106
4
votes
3 answers
Which is faster for writing files C# (.NET) or PERL?
We have a lot of old legacy Perl scripts that connect to a MS SQL db process some records, and make files. Over time, the daily transaction size grew and these scripts are becoming more and more expensive.
Moreover, the Databases grew with more and…

Sam
- 946
- 3
- 11
- 22
4
votes
7 answers
Java text file size (before file is closed)
I am collecting full HTML from a service that provides access to a very large collection of blogs and news websites. I am checking the HTML as it comes (in real-time) to see if it contains some keywords. If it contains one of the keywords, I am…

Andrew
- 1,157
- 1
- 20
- 37
4
votes
2 answers
How to solve Flutter error while trying to write in a file: "OS Error: Operation not permitted, errno = 1"?
I am trying to write in a .txt file in my flutter program. I am using Permission_handler package and when I run the code (using mi 10) the app ask for permission to access to media and file and I hit allow, and the Debug console says "I/flutter…

afsane
- 117
- 3
- 11
4
votes
4 answers
Error in Writing to Image file from PHP
I am attempting to write to an image file from a blob.
if($_POST['logoFilename'] != 'undefined'){
$logoFile = fopen($_POST['logoFilename'], 'w') or die ("Cannot create ".$_POST['logoFilename']);
fwrite($logoFile, $_POST['logoImage']);
…

GAgnew
- 3,847
- 3
- 26
- 28
4
votes
1 answer
Why does my PDF file open as blank when I save it from PDF data string in Node.js
I'm trying to write a PDF file to disc from a Node.js application. I can create the file but when I open it, it's blank. It's not 0 size so obviously data is being written to it, but I need to figure out how to see the data I expect to see when I…

gib65
- 1,709
- 3
- 24
- 58
4
votes
1 answer
Node.js: Writing to system files with fs.writeFileSync
I am trying to write to a system file under /sys/kernel/config/usb_gadget with fs.writeFileSync but when writing "" as the contents, the file remains unchanged (with original contents in tact) and results in
Error: EBUSY: resource busy or locked,…

Sterling Butters
- 1,024
- 3
- 20
- 41