This answer assumes that you are doing more than just creating a File object, which you are actually creating a file on the file system. (An A File object is just a logical representation of an entry in a file system that may or may not exist.) If you really just create a File object, read the EJP answer - at that point, you basically just got a name. It does not have a "type" or a "format".
The extension is part of the name. The operating system may try to use this to display another icon or launch a specific application by double-clicking on the icon or something else, but it really is just part of the name.
The file basically consists of:
- The name you specify when creating it
- The bytes that you write in it
- Metadata such as access control
If you do not intentionally add metadata, it is usually just inherited (default permissions, etc.).
You can write any data in any file - just because the file has the extension .txt does not mean that it is definitely a text file. For example, it may contain content that is actually MP3-encoded audio files. Regardless of whether the OS uses the file extension or content to determine what to do with the file, it depends on the OS.
source share