Questions tagged [file-handling]

file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files

2915 questions
6
votes
0 answers

How to test if a file can be created in Python

While I understand os.access() can be used to check if an existing file can be read or written, I was wondering whether a similar method can be used to see whether a file can be created. I need to create a file at some point in my code, after…
mrgou
  • 1,576
  • 2
  • 21
  • 45
6
votes
1 answer

Read from file and write to cout in one line

Is there any way I can perform both these actions in one line: fscanf(fp,"%d",&n); std::cout<
leo valdez
  • 259
  • 1
  • 15
6
votes
1 answer

Capturing data being written to open file descriptor

Is it possible to write a program that's able to take another application's open file descriptors and just pass along their contents without any conversion? Let's say App A has an open FD to some file on disk that it's writing data to. I'd like to…
user1610950
  • 1,837
  • 5
  • 33
  • 49
6
votes
5 answers

How many bytes will be required to store number in binary and text files respectively

If I want to store a number, let's say 56789 in a file, how many bytes will be required to store it in binary and text files respectively? I want to know how bytes are allocated to data in binary and text files.
programmer
  • 57
  • 1
  • 5
6
votes
3 answers

Randomly distribute files into train/test given a ratio

I am at the moment trying make a setup script, capable of setting up a workspace up for me, such that I don't need to do it manually. I started doing this in bash, but quickly realized that would not work that well. My next idea was to do it…
Mønster
  • 61
  • 1
  • 4
6
votes
2 answers

Difference between int fpurge() and int fflush() in C

Can anyone please explain me about difference between fpurge(FILE *stream) and fflush(FILE *stream) in C? Both fflush() and fpurge() will discard any unwritten or unread data in the buffer. Please explain me the exact difference between these two…
c.monica
  • 61
  • 1
  • 2
6
votes
1 answer

Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property

I am saving an image file from jsp and renaming it in the controller The problem is that same piece of code is working in one part of the controller and not working in another part of the controller here is the jsp code which is same in both…
Md Faisal
  • 2,931
  • 8
  • 29
  • 34
6
votes
1 answer

Using fscanf and fprintf together in C

#include #include #define FILE_NAME "ff.txt" int main() { char x[10],y[10]; FILE *fp; fp = fopen(FILE_NAME, "r+"); if (fp == NULL) { printf("couldn't find %s\n ",FILE_NAME); …
Aneesh Dogra
  • 740
  • 5
  • 30
6
votes
4 answers

How to extract data from a line which has fields separated by '|' character in C++?

I have data in the following format in a text file. Filename - empdata.txt Note that there are no blank space between the lines. Sl|EmployeeID|Name|Department|Band|Location 1|327427|Brock Mcneil|Research and Development|U2|Pune 2|310456|Acton…
Anish Kumar
  • 103
  • 10
6
votes
1 answer

reading and modifying large text files 3-5GB

I have a rather large file consisting of several million lines and there is the need to check and remove corrupt lines from the file. I have shamelessly tried File.ReadAllLines but it didn't work. Then I tried to stream lines as below reading from…
mechanicum
  • 699
  • 3
  • 14
  • 25
6
votes
1 answer

Perl implicit close resets the $. variable

The documentation for Perl's close states that $. isn't reset if you use the implicit close done by open. I was trying to see exactly what this meant, but couldn't get it to happen. Here's my script: use strict; use warnings; use autodie; my @files…
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
6
votes
3 answers

How severe is it if we do not close a file in Perl?

How severe is it if we do not close a file in Perl? Will it affect the program or file if I access it again in the same program?
Daanish
  • 1,061
  • 7
  • 18
  • 29
6
votes
2 answers

Java Parallel File Processing

I have following code: import java.io.*; import java.util.concurrent.* ; public class Example{ public static void main(String args[]) { try { FileOutputStream fos = new FileOutputStream("1.dat"); DataOutputStream dos = new…
Arpssss
  • 3,850
  • 6
  • 36
  • 80
5
votes
1 answer

Error while downloading the dataframe from Streamlit web application after data preprocessing

The required task is deploy the data preprocessing web application on Streamlit in which user can upload the raw dataframe and download the processed dataframe. I am trying to download the file on which data preprocessing like missing value…
5
votes
2 answers

Create a file descriptor

I want to create a file descriptor in C whose value i will specify in code. I have a integer variable which specifies the value of file descriptor to be created. For example i may need a file descriptor whose value is 5 and later associate that with…
mukesh
  • 726
  • 1
  • 11
  • 27