This answer assumes you're doing more than just creating a File
object - that you're actually creating a file on the file system. (A File
object is just a logically representation of a file system entry which may or may not exist.) If you're really just creating a File
object, read EJP's answer - at that point, you've basically just got a name. That doesn't have a "type" or a "format".
The extension is just part of the name. The operating system may try to use that to display a different icon, or launch a specific application when you double-click on the icon, or whatever - but it's really just part of the name.
Fundamentally, a file consists of:
- The name you specify when you create it
- The bytes you write in it
- Metadata such as access control
Unless you deliberately add metadata, it's typically just inherited (default permissions etc).
You can write any data in any file - just because a file has an extension of .txt
doesn't mean it's definitely a text file. It could have content which is actually MP3-encoded audio data, for example. Whether the OS uses the file extension or the content to work out what to do with the file is up to the OS.