What type of File is created when we create new File without the extension?

In java, when we create a file, we create files using the name of the extension. For example :

File file = new File("D:/light.txt");

I would like to know what type of file format do we get when we create a file without the file extension type. For example :

File file = new File("D:/light");
Jon Skeet
people
quotationmark

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.

people

See more on this question at Stackoverflow