what is the main difference between a file with .db extension and a file with .txt extension while I save both of them from a text editor?

0

What is the difference between a file with .db extension and a normal file with .txt extension , leaving the fact that a .db extension is for a database file and .txt makes a normal text file.

I open a text editor and type 5 entries:

First Entry : Ghazal
Second Entry : Qateel Shifai
Third Entry : Faiz Ahmed Faiz
Fourth Entry : Jigar Moradabadi
Fifth Entry : Ahmed Faraz

What do I gain if I save the above data in a file with a .db extension while not saving it in a file with a .txt extension ?

Suhail Gupta

Posted 2013-01-08T17:06:58.800

Reputation: 1 655

Answers

2

For the file: nothing.

The file will be treated in exactly the same way.

If you try to open the file with a program then there can be a difference depending on the program.

E.g. if I use somepictureViewer picture then there are three things which can happen:

  1. The program will look inside the file to determine it type. This is why many files start with something called MagicNumbers. (e.g. a JPEG file will usually start with JFIF in the first bytes. A .gif file with GIF87 or GIF89. A PDF with PDF13, etc etc. This is the clean, neat way.
  2. The program will try to open the file and assume it is the default format. This might leads to some messed up contents if it guesses wrong.
  3. The program will look at its extension and assume that a specific extension belongs to a specific file format. This can work out great and this can produce horrible results.

The most obvious example in this is with windows, where I can open a file called demo.xls and the default settings make the assumption that a file ending in .xls is an excel file. If it is, then things work great. If it happens to be a misnamed picture (and yes, I have seen this in the wild with clueless users trying to get a picture inside an excell sheet) then things will simply go wrong.

But for the file itself: Nothing changes.

Hennes

Posted 2013-01-08T17:06:58.800

Reputation: 60 739

and can you please answer the ..what do I gain part of the question ? – Suhail Gupta – 2013-01-08T17:25:54.460

Depending on the OS: Either nothing or automatic opening with a specific program. (Read: if you use windows you can set it to automatically open all programs with an extension of your choice with a chosen program). – Hennes – 2013-01-08T17:31:16.630

as an application developer what do I gain ? – Suhail Gupta – 2013-01-08T17:35:19.540

Nothing at all since the file stays precisely the same. – Hennes – 2013-01-08T17:39:02.527

1@SuhailGupta To Hennes' point, as an application developer, you can be confident that your file is not going to be opened in Notepad on your end user's system by default, and help keep it from being inadvertently deleted. So, in the opposite, by naming it .db, you gain having it NOT open with a specific program by default. A filename and extension can convey a file's intended purpose or relationship with other files. – maxwellb – 2013-01-08T18:42:09.140

@SuhailGupta: Agree with whatever maxwellb said, although if you don't want your users messing with your program's data files easily, use a binary format instead of a text-based one. – Karan – 2013-01-08T19:22:54.867

1

Just a note on the 'what do I gain?' part of the question.

If you luck out, and have a particular database program that reads flat files with a .db extension, and saves files in the format you've specified - ie 1 record per file (maybe with a colon at the beginning of the record) - then when you double-click that .db file, it will open in the database program.

So if you develop an application that reads files in that format, you can use associations to set the file to open your program by default (on double-click or right-click, open)

mcalex

Posted 2013-01-08T17:06:58.800

Reputation: 2 315

When I try to open the .db file that looked like this via MySql GUI tool, I see nothing in it

– Suhail Gupta – 2013-01-08T18:04:50.870

Therefore mysql's .db files are not formatted like your .db file. – mcalex – 2013-01-09T00:48:57.573