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
8
votes
7 answers

How to handle incomplete files? Getting exception

I need to create a java program which will create thread to search for a file in particular folder(source folder) and pick the file immediately for process work(convert it into csv file format) once it found the file in the source folder. Problem i…
raja
  • 4,043
  • 6
  • 30
  • 24
8
votes
1 answer

TypeError: write() argument must be str, not bytes while saving .npy file

I tried running the code in a keras blog post. The code writes to a .npy file as follows: bottleneck_features_train = model.predict_generator(generator, nb_train_samples // batch_size) np.save(open('bottleneck_features_train.npy',…
Atul Balaji
  • 804
  • 4
  • 15
  • 29
8
votes
4 answers

Java - Random line read

I am programing an Android app, and would like my program to read a random line of a file. How would I go about doing that?
Tyler Wall
  • 3,747
  • 7
  • 37
  • 52
8
votes
5 answers

Find/Remove oldest file in directory

I am trying to delete oldest file in directory when number of files reaches a threshold. list_of_files = os.listdir('log') if len([name for name in list_of_files]) == 25: oldest_file = min(list_of_files, key=os.path.getctime) …
cosmos
  • 2,263
  • 1
  • 17
  • 30
8
votes
1 answer

Open file for reading and writing(not appending) in perl

Is there any way with the standard perl libraries to open a file and edit it, without having to close it then open it again? All I know how to do is to either read a file into a string close the file then overwrite the file with a new one; or read…
GlassGhost
  • 16,906
  • 5
  • 32
  • 45
8
votes
1 answer

Reading/Writing a structure into a binary file

I am running a program with 3 structures and what I am doing to read/write in the binary file is the following: struct Medico { int Id_Doctor; int Estado; char Nombre[60]; char Clave_Acceso[20]; char Especialidad[40]; struct…
drodri420
  • 191
  • 2
  • 6
  • 14
8
votes
5 answers

Performance of fwrite and write size

I'm writing out a large numerical 2 dimensional array to a binary file (final size ~75 MB). I'm doing this on a linux system. First, is there a better method or syscall other than fwrite to write the file as fast as possible? Second, if I should…
Peter Smith
  • 849
  • 2
  • 11
  • 28
8
votes
3 answers

Delete The First Bytes of a Random Access File in Java

I'm writing bytes to a random access file. After completing the operation, I want to delete the first 100 bytes from the file. How can I achieve this? Thanks in advance.
sirin
  • 167
  • 4
  • 9
8
votes
1 answer

How to read a file by setting correct offset and position and write to the response in Nodejs with manual buffering?

I want to read a file in 64byte interval. And I also do not want to use any functionality which interanlly implements buffering. I wanted to do buffering manually. So I started using fs.read(). I tried hard but I really don't know how to set…
Kishore Kumar Korada
  • 1,204
  • 6
  • 22
  • 47
8
votes
6 answers

Fastest Way To Calculate Directory Sizes

what is the best and fastest way to calculate directory sizes? For example we will have the following structure: /users /a /b /c /... We need the output to be per user directory: a = 1224KB b = 3533KB c = 3324KB ... We plan…
Justin
  • 42,716
  • 77
  • 201
  • 296
8
votes
3 answers

fgetc(): Is it enough to just check EOF?

In various examples found on the web fgetc() is used like this: FILE *fp = fopen(PATH, "r"); if (fp == NULL) { perror("main"); exit(EXIT_FAILURE); } int ch; while (ch = fgetc(fp) != EOF) { // do something } But according to the…
helpermethod
  • 59,493
  • 71
  • 188
  • 276
8
votes
0 answers

Why doesn't Files.newInputStream(path) support the available method on FIFOs?

Take this simple test class: public class InputStreamTest { public static void main(String[] args) throws IOException { byte[] buf = new byte[100]; Path path = Paths.get(args[0]); System.out.println("File " + path); …
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
8
votes
4 answers

How to use relative path instead of absolute path?

So I am having a strange issue with Java. I'm reading a writing files, so the path is important to me. I would like all files to be written and read from the relative path (i.e in the folder with the rest of my class and java files). I write files…
Blackbinary
  • 3,936
  • 18
  • 49
  • 62
8
votes
3 answers

How should I store a time_t timestamp to a file using C?

For a small todo program that I am writing, I have timestamps that are of this form time_t t = time(NULL); and are saved every time a task is entered to denote the time that it was entered. I want to store the tasks to a plain text file, so that…
Lazer
  • 90,700
  • 113
  • 281
  • 364
8
votes
1 answer

Swagger defination, how to specify that a file is returned?

I want to download a file from the server, and I define the swagger file as follows: swagger: '2.0' ################################################################################ # API…
Niubility
  • 577
  • 5
  • 19