I am designing a software and want to save data in a txt file. but dont want the user to open them as txt file, only the app should do it.
Is this possible? if yes, how? I've searched in google, but not any good reason to help me out.

Recommended Answers

All 9 Replies

Make a new extension (you can check filext.com to make up one that is probably not in use) then when you double click on it you can tell Windows to use your app to open it.

Note that using a different extension won't prevent people from opening the file in a text editor. It'll just stop a text editor from being the default application that will open when you double click on it in your file manager (unless the user then selects a text editor as the default for that extension).

what is any way to prevent the user from opening those inside the file?

what is any way to prevent the user from opening those inside the file?

If a file is on my computer, I'll find a way to open it. Files that try to "prevent" me from accessing them are files that I don't want on my computer. Now as far as programs that store information on my computer and tell me I shouldn't try to monkey around with them for my own good and they are purposefully saved without write and execute privileges, I'm cool with that. But "prevent" me? It's my computer. I decide what I want on it. Maybe I'm hung up on the word "prevent". Having a big neon sign saying "Warning: If you edit this file, your program will no longer work!", no problem. Not allowing me access to files on my own computer without YOUR program and ONLY YOUR program "letting" me? I have a problem with that on a philosophical level and personal experience tells me it's usually spam/malware. Care to elaborate what you are trying to accomplish and why?

what is any way to prevent the user from opening those inside the file?

I have no idea what you mean by that but if you encrypt the file before you save it then it can still be opened by a text editor but any attempt to modify it will just invalidate the file.

Well, is fine, I will save it in a .txt file then, no need for extra things. more work on a program doesnt mean it is a better program.

Thanks for the support all of you, it was helpful

A file reference is just the portion of the file name after the last period. The file extension is .txt which typically indicates that the file contains text data. To create your own file extension all you demand to do is to place the desired extension after the last period in the filename.

One way to discourage the user from opening the file with a text editor is to store binary data in the file. You could encrypt the file to produce a binary data file.

You could use simple obfuscation, like base 64 encoding. If the data is fixed length, you could store it in the executable, or save it as a binary file, maybe a .bin or .dat extension. It will be readable as text but the data will be garbled. If you don't identify the encoding it would require trial and error or decompiling to figure it out. Not impossible but not worth the time for the vast majority of people.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.