file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files
Questions tagged [file-handling]
2915 questions
3
votes
4 answers
How to read json file and serialize it in custom class?
I have following JSON saved in menu.json file:
{
"menu": {
"menuitems": [
{
"label": "Account",
"listview": "Account List"
…

Bhushan Firake
- 9,338
- 5
- 44
- 79
3
votes
2 answers
How to see file handles like with "lsof -l"?
I did the commands (source):
$ exec 3>/tmp/thirdfile
$ exec 4>/tmp/fourthfile
$ echo drib >&3
$ echo drab >&4
$ echo another drib >&3
$ echo another drab >&4
$ exec 3>&-
$ exec 4>&-
How can I see the file handles, something like with lsof -l?

Léo Léopold Hertz 준영
- 134,464
- 179
- 445
- 697
3
votes
1 answer
File Handling with LinkList in C++
PROBLEM: I am trying to write (binary writing) an object of Doubly Linked List onto File & write from it too.
I have to write object's complete contents, then load it from file, and store it into new object to re-create the list in FIFO order.
I…

InamTaj
- 276
- 2
- 7
- 15
3
votes
1 answer
how to use `with open` in my own class method?
I want to define a class method to write directly to a file without explicitly closing the file. But if I return the object like so:
class sqlBuilder(object):
...
def save_sql_stat(self, file_n, mode = 'w'):
try:
with…

LarsVegas
- 6,522
- 10
- 43
- 67
3
votes
3 answers
How to efficiently append a new line to the starting of a large file?
I want to append a new line in the starting of 2GB+ file. I tried following code but code OUT of MEMORY
error.
myfile = open(tableTempFile, "r+")
myfile.read() # read everything in the file
myfile.seek(0) # rewind
myfile.write("WRITE IN THE FIRST…

D.Rosado
- 5,634
- 3
- 36
- 56
3
votes
2 answers
Write a JPG image file in C
I read JPEG image file and store its bits to a text file. Now I wanna convert back to valid JPEG image using those bits in the text file. I have tried writing a binary file but it doesn't retrieve the image file.
Please steer me to the right…

Sam
- 423
- 2
- 9
- 23
3
votes
3 answers
Reading the content of file other than ".txt" file
How can i read content of a file which is not a simple text file in c/c++? For example, I want to read image file such as .jpg/.png/.bmp and see the value at certain index,to check what colour it is? or if I have a .exe/.rar/.zip and want to know…

someone_ smiley
- 1,006
- 3
- 23
- 42
2
votes
2 answers
How to store many file handles so that we can close it at a later stage
I have written a small program in python where I need to open many files and close it at a later stage, I have stored all the file handles in a list so that I can refer to it later for closing.
In my program I am storing all the file handles (fout)…

Gaara
- 161
- 1
- 2
- 4
2
votes
5 answers
Check if file is present in some directory in c++
I am reading a file from some directory using visual c++. How do i check if that file exists or not.
If i use:
file.open("file.txt", ios::in);
where file is a member of fstream. This creates a file ifthat file is not present.
How can i check if…

digvijay
- 189
- 1
- 5
- 16
2
votes
2 answers
How to handle lots of application resources in .net application?
I'm developing a wpf app which contains a dashboard with buttons ordered by category. Each button opens a resource, this can be a PDF, a video, etc. In total there are 12 categories with 60 subjects and teaching materials per category. So 720 in…

Arne W
- 53
- 6
2
votes
2 answers
Write csv files with Byte Order Mark (BOM) using c++?
I am trying to create a csv file with UTF8 with BOM using c++. Can anybody help me, how to do this?

Nithin
- 921
- 3
- 10
- 17
2
votes
3 answers
Exists, Read and Write in just one step
I'm trying to find out if a file exists, if it does, verify if the css style already exists, if not, write them at the end of the file ...
I'm doing all this already but in 3 steps:
Does the file exist?
FileInfo fi= new…

balexandre
- 73,608
- 45
- 233
- 342
2
votes
1 answer
Database file not resetting properly, unless the app is restarted
I'm creating a .NET MAUI Android app which uses a built-in local SQLite database file, CommunityMVVMToolKit simply because it's great and EntityFramework Core for mapping objects into database records and vice-versa.
I'm new to this framework, and…

MaxKolac
- 21
- 4
2
votes
5 answers
C# - How to list the files in a sub-directory fast, optimised way
I am trying to list the files in all the sub-directories of a root directory with the below approach. But its taking much time when the number of files are in millions. Is there any better approach of doing this.
I am using .NET 3.5 so can't use…

Mayur J
- 371
- 1
- 7
- 14
2
votes
2 answers
strtok Invalid read of size 1
I am reading in a text file as a char array and separating up the values by the space separator using strtok and placing each separated word into its own sub array in inputArray.
This runs fine in CLion however if I compile via command line, I get…

ben
- 21
- 3