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.
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?
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?
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.
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.