Questions tagged [file-io]

File I/O is input/output that involves the file system. This could include performing operations on directories and files, such as creation and deletion, reading files, and writing output to files.

For an introduction on File I/O in C, see C Programming / File I/O on Wikibooks.

21104 questions
127
votes
80 answers

File I/O in Every Programming Language

This has to be a common question that all programmers have from time to time. How do I read a line from a text file? Then the next question is always how do i write it back. Of course most of you use a high level framework in day to day programming…
Brock Woolf
  • 46,656
  • 50
  • 121
  • 144
125
votes
2 answers

Android file chooser

I want to make a file uploader. And I hence I need a file chooser but I don't want to write this by myself. I find OI file manager and I think it suits me. But how can I force user to install OI file manager? If I cannot , is there a better way to…
Bear
  • 5,138
  • 5
  • 50
  • 80
125
votes
7 answers

Append to a file in Go

So I can read from a local file like so: data, error := ioutil.ReadFile(name) And I can write to a local file ioutil.WriteFile(filename, content, permission) But how can I append to a file? Is there a built in method?
seveibar
  • 4,403
  • 4
  • 30
  • 31
125
votes
10 answers

How to write file if parent folder doesn't exist?

I need to write file to the following path: fs.writeFile('/folder1/folder2/file.txt', 'content', function () {…}); But '/folder1/folder2' path may not exists. So I get the following error: message=ENOENT, open /folder1/folder2/file.txt How can I…
Erik
  • 14,060
  • 49
  • 132
  • 218
125
votes
10 answers

open() gives FileNotFoundError / IOError: '[Errno 2] No such file or directory'

I am trying to open the file recentlyUpdated.yaml from my Python script. But when I try using: open('recentlyUpdated.yaml') I get an error that says: IOError: [Errno 2] No such file or directory: 'recentlyUpdated.yaml' Why? How can I fix the…
Santiago
  • 1,984
  • 4
  • 19
  • 24
123
votes
5 answers

Create a File object in memory from a string in Java

I have a function that accepts File as an argument. I don't want to create/write a new File (I don't have write access to filesystem) in order to pass my string data to the function. I should add that the String data don't exist in a file (so I…
Jon Romero
  • 4,062
  • 6
  • 36
  • 34
123
votes
8 answers

Replace string within file contents

How can I open a file, Stud.txt, and then replace any occurences of "A" with "Orange"?
Joey
  • 1,297
  • 2
  • 8
  • 5
123
votes
12 answers

fs.writeFile in a promise, asynchronous-synchronous stuff

I need some help with my code. I'm new at Node.js and have a lot of trouble with it. What I'm trying to do: Fetch a .txt with Amazon products (ASINs) ; Fetch all products using the amazon-product-api package; Save each product in a .json…
122
votes
2 answers

Read/write files within a Linux kernel module

I know all the discussions about why one should not read/write files from kernel, instead how to use /proc or netlink to do that. I want to read/write anyway. I have also read Driving Me Nuts - Things You Never Should Do in the Kernel. However, the…
Methos
  • 13,608
  • 11
  • 46
  • 49
118
votes
18 answers

file_put_contents - failed to open stream: Permission denied

I am trying to write a query to a file for debugging. The file is in database/execute.php. The file I want to write to is database/queries.php. I am trying to use file_put_contents('queries.txt', $query) But I am getting…
Hailwood
  • 89,623
  • 107
  • 270
  • 423
117
votes
7 answers

Cross-browser custom styling for file upload button

I'm trying to style a file upload button to my personal preferences, but I couldn't find any really solid ways to do this without JS. I did find two other questions about this subject, but the answers there either involved JavaScript, or suggested…
Joeytje50
  • 18,636
  • 15
  • 63
  • 95
116
votes
1 answer

What are `Zone.Identifier` files, and how do I prevent them from being created?

I often see files named 'blabla.exe:Zone.Identifier' when monitoring I/O with Process Monitor. The files are seen on network-drives. What are Zone.Identifier files? What does the colon mean in the filename? Is the colon related the file's extended…
Benjamin
  • 10,085
  • 19
  • 80
  • 130
116
votes
11 answers

How to delete migration files in Rails 3

I would like to remove/delete a migration file. How would I go about doing that? I know there are similar questions on here but as an update, is there a better way than doing script/destroy? Also, should I do a db:reset or db:drop if I remove/delete…
alvincrespo
  • 9,224
  • 13
  • 46
  • 60
115
votes
11 answers

How to create an Excel File with Nodejs?

I am a nodejs programmer . Now I have a table of data that I want to save in Excel File format . How do I go about doing this ? I found a few Node libraries . But most of them are Excel Parsers rather than Excel Writers .I am using a Linux Server .…
geeky_monster
  • 8,672
  • 18
  • 55
  • 86
112
votes
6 answers

How to get the location of the DLL currently executing?

I have a config file that I need to load as part of the execution of a dll I am writing. The problem I am having is that the place I put the dll and config file is not the "current location" when the app is running. For example, I put the dll and…
Vaccano
  • 78,325
  • 149
  • 468
  • 850