File types are born in the vast lands of Atlantis when the Moon and the sun are perfectly aligned to shine onto the altar of the mighty windows; then you have to sacrifice a penguin to the mighty macintosh, and in the light of the shrine you will find that a new file type is born! Jokes aside, you'd read/write your file just as you would do with any other file
A file extension is just an identifier. It doesn't do anything by itself. So just save the file as whatever.yourawesomeextension and it will be the same as saving it as whatever.txt
Yes. You can open a JAR file as an image if it is in png format. File extension doesn't do anything except being more understandable for the user.
I know - I was just trying to hint to OP that file extensions don't really mean anything, especially on Linux
Depends on the extension & program. For example i can create a .dat file, doesn't mean minecraft could use it unless that file PROPERLY followed the NBT format. TLDR; The extension, file content and program used matters a lot.
Of course - however if I rename the .dat file to just "hello", and then edit minecraft to reflect the new path changes, then it'll still read it fine. And of course it must follow the NBT format - I never said otherwise. I said that the file extension doesn't change anything to do with how the file is read and how data is written to it, hence why Linux doesn't use them
for writing to/from a file, it depends on the file format you want it to have. yml, json, whatever dat is technically called, standard txt, ect. you use specific methods of saving to and from a file. it depends on the format you want. if you want a simple txt read/writer, the Files java api has this for you already, or you can manually do it yourself with FileReader and FileWriter objects. a quick google of this would tell you more in depth explanations.
Other fun fact: some apps use file extensions like .conf etc... It's not off-topic. We're explaining to the OP what is really file extensions True. A file is just a collection of bytes. You can use a text format like json, yaml, etc... or use a "raw" format like NBT (Usually named foo.dat) which write directly bytes, int etc... in an OutputStream using a byte (NBTTagEnd's type id) to separe values