Skip to content
Advertisement

How to create my own file extension like .odt or .doc? [closed]

I am working on a document processing project like Microsoft word (Academic project).

Is there any quick way to create my own file extension? Is there third-party software that allows you to create your own file extension? (I.e. myfile.funny?)

Advertisement

Answer

A file extension is just the portion of the file name after the last period.

For example in the path:

C:UsersTestsMy Documentsfile.txt

The file extension is .txt which typically indicates that the file contains text data. To create your own file extension all you need to do is to place the desired extension after the last period in the filename.

In Java you can create a file using an object of type File like this:

File file = new File("file.txt")

The file will be created in the current working directory and will have the extension txt because this is the value after the final period in the file name.

A file format refers to the layout of data inside a file. Creating a custom file format involves thinking about how you want to store your data within the file, and writing it to the file in a way which matches that layout.

For example if I had an address book application I might decide to store peoples names and phone numbers, separated by tabs and save this data in a file with extension address

My AddressBook.Save() function might look something like this Java code. It should be noted that I haven’t programmed in Java for a number of years and mistakes are likely.

void Save(File file)
{
 FileWriter writer = new FileWriter(file);

foreach (AddressBookEntry entry in this.entries)
{
this.SaveEntry(entry,writer);
}
} 


void SaveEntry(AddressBookEntry entry,  FileWriter writer)
{
  String record = entry.getFirstName() + "t" + entry.getLastName() + "t" +
  entry.getPhoneNumber();
  writer.write(record, 0, record.length();
}

If we had an address entry like this:

First Name:Test
Last Name: Bob
Phone Number=555-1212

Then the entry would appear in the .address file as follows

Test Bob 555-1212

I hope that’s helped explain the difference between a file extension and a file format and has gone some way to showing you how to create your own format, with a custom extension.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement