Questions tagged [file-handling]

File handling refers to the set of tools, functions, and libraries to work with files and file handles. Creating, writing, appending, moving, and deleting files fall in this domain.

File handling refers to the set of tools, functions, and libraries to work with files and file handles. Creating, writing, appending, moving, and deleting files fall in this domain.

163 questions
243
votes
13 answers

Is it a bad practice to store large files (10 MB) in a database?

I am currently creating a web application that allows users to store and share files, 1 MB - 10 MB in size. It seems to me that storing the files in a database will significantly slow down database access. Is this a valid concern? Is it better to…
B Seven
  • 3,105
  • 3
  • 16
  • 14
131
votes
8 answers

Difference between '\n' and '\r\n'

Yes yes, I am aware that '\n' writes a newline in UNIX while for Windows there is the two character sequence: '\r\n'. All this is very nice in theory, but my question is why? Why the carriage return character is extra in Windows? If UNIX can do it…
sukhbir
  • 1,479
  • 2
  • 11
  • 9
81
votes
7 answers

Should temporary files be saved to /tmp or the current working directory?

I have a program that needs to generate temporary files. It is written for cluster machines. If I saved those files to a system-wide temporary directory (eg: /tmp), some users complained the program failed because they didn't have proper access to…
ABCD
  • 1,166
  • 1
  • 8
  • 13
70
votes
6 answers

Should I pass in filenames to be opened, or open files?

Suppose I have a function that does things with a text file - for example reads from it and removes the word 'a'. I could either pass it a filename and handle the opening/closing in the function, or I could pass it the opened file and expect that…
Dan Oberlam
  • 1,271
  • 1
  • 9
  • 21
53
votes
3 answers

What is the benefit of writing to a temp location, And then copying it to the intended destination?

I am writing an application that works with satellite images, and my boss asked me to look at some of the commercial applications, and see how they behave. I found a strange behavior and then as I was looking, I found it in other standard…
Devdatta Tengshe
  • 2,514
  • 4
  • 21
  • 22
23
votes
1 answer

Why would anyone use multipart/form-data for mixed data and file transfers?

I'm working in C# and doing some communication between 2 apps I'm writing. I have come to like the Web API and JSON. Now I am at the point where I am writing a routine to send a record between the two servers that includes some text data and a file.…
Ian
  • 395
  • 1
  • 2
  • 9
22
votes
1 answer

How do I test a file reader?

I am working on a project with a few file formats. Some formats are specified by .xsds, others by documentation on their respective websites, and some are custom in-house formats that have no documentation. Mwahahahaha. What's the problem? I would…
20
votes
4 answers

Using flat files vs database/API as a transport between a frontend and backend

I've got an application which has generated a rather heated discussion between a couple of the developers. Basically, it's split into a web layer and a backend layer. The web layer collects information by a simple web form, stashes this data as a…
19
votes
3 answers

What is a good design for allowing backwards compatibility of files between different versions of software?

What is a good design for allowing backwards compatibility of a file type between different versions of software? For instance, how does microsoft get word 2007, 2010 and 2013 etc... to all open docx files, but different editions can save more /…
JJBurgess
  • 191
  • 1
  • 5
19
votes
5 answers

What's the best practice for naming uploaded images?

Suppose I have a form in my web application where users can upload a profile picture. I've got few requirements about file size, dimensions etc, but when the user uploads the image, how should I name them on my system? I suppose it would need to be…
Rowan Freeman
  • 3,478
  • 4
  • 30
  • 41
19
votes
7 answers

Is it necessary to read every single byte to check if a copied file is identical to the original?

I recently learned of a program called Total Commander. It's a Windows Explorer replacement and has its own stuff to copy files. To check whether the files are identical, instead of calculation a CRC, it literally checks every single byte, one at a…
Koen027
  • 293
  • 2
  • 6
16
votes
7 answers

Best way to handle delimited files

So typically a CSV file uses a comma and the return character as it's field and line delimiters. This runs into obvious problems with text which can contain both these characters. Obviously there are options there (escaping them) but how do people…
Jon Hopkins
  • 22,734
  • 11
  • 90
  • 137
16
votes
5 answers

Test Driven Development: A good/accepted way to test file system operations?

I am working on a project at the moment that generates a table (among other things) based on the contents of a file-system, and in turn does some meta-data modifications on the things it finds. The question is: how should tests be written around…
Kirbinator
  • 263
  • 1
  • 2
  • 8
11
votes
1 answer

Base64 in Json: Is it a Good Idea for Rest API?

I am developing a Rest API, and I am asking myself: Is it a good Idea to put base64 encoded data in Json, e.g. for file uploads? What if the base64 contains some of {,},: characters and breaks the json content? If is not a good idea, what…
Dimitrios Desyllas
  • 451
  • 2
  • 4
  • 16
10
votes
5 answers

Is it bad practice to read large file in constructor?

So, I am trying to create an English language trie data structure implementation in C++. I have created a Trie and TrieNode class. The TrieNode class takes in its constructor a vector that is a list of words to construct the Trie from. My…
Bassinator
  • 714
  • 1
  • 8
  • 22
1
2 3
10 11