Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?)

like image 817
mahesh Avatar asked Jan 19 '13 09:01

mahesh


People also ask

How do I create a file extension in Windows 10?

Right-click the File Type Associations node, and select New Association from the pop-up menu. Complete the first step of the dialog box by completing the following information, and then click Next: Extension—Enter a new file name extension.

How do I add a file extension?

Step 2: Right-click the file name and select Rename (or left-click and hold down the button for one second). Enter the new extension like so: After entering the new extension hit the Enter (return) key. Windows will give you a warning that the file may not work properly.


2 Answers

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

For example in the path:

C:\Users\Tests\My Documents\file.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.

like image 117
2 revs Avatar answered Nov 09 '22 17:11

2 revs


This is not Java related. Pick an extension that no one else is using and when you write the file using Java, just append the extension to the filename.

like image 41
JohnJohnGa Avatar answered Nov 09 '22 17:11

JohnJohnGa