What type of file is created when creating a new file without extension?

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

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

I would like to know what file format we will get when we create a file without a file extension type. For instance:

 File file = new File("D:/light"); 
+5
source share
2 answers

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.

+4
source

What type of file is created when creating a new file without extension?

A file is not created at all, and there is only one type of File .

In java, when we create a file, we create files using the extension name.

Or not.

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

I would like to know what file format we get when we create a file without a file extension type.

No. You are not getting any file format at all, because you are not getting a file: only the File object in memory.

For example: File file = new File("D:/light");

You can create all the examples you need, but the file is not created, and there is no file format.

In any case, Java does not care about file name extensions. Perhaps your operating system, but a different story.

+2
source

All Articles