Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Creating a new file extension in a program

I'm aiming to create a new file extension (possibly more than one) for a program I'm creating. So, after looking around for a bit, I found a number of sources on the subject, listed below, just in case anyone wants to look at them and get the general idea of what I have been looking at.

Utilising a file association in a Java application

Create registry entry to associate file extension with application in C++

Associating file extensions with a program

http://support.microsoft.com/?scid=kb%3Ben-us%3B185453&x=6&y=11

http://www.rgagnon.com/javadetails/java-0592.html

http://www.rgagnon.com/javadetails/java-0480.html

Also, note that the Microsoft support one is actually a Visual Basic lesson, but I was just trying to see if there were any similarities in the registry changing.

Most of them generally talk about doing some registry editing so that Windows can recognize the new file and know what to do with it. Then I stumbled upon this document by Oracle, which claims that you are able to do all of the above with some (seemingly) simple Java code. I figure if it's that easy, though, somebody would have pointed it out already. Also, that document is from 2006. I've got a number of questions, which I understand can be a lot to go through, so if anyone takes time out to answer this, thanks a bunch!

  • What's really the best way to go about creating and associating a file type for a Java program?
  • If the Oracle method is used, is it done in a completely separate program? I would assume you don't want the file type being created and associated every time the program runs, and from what I've seen, that will actually return errors.
  • I want other people (only Windows users) to be able to easily install the program, but I'm on Windows 7 64-bit. Are there any changes I should be aware of to make the association also compatible with 32-bit systems?
  • Are the changes easily and completely reversible with either method (i.e. if I just wanted to create a test file extension)?

I couldn't find any extensive sources on teaching how to do this kind of stuff with no previous knowledge of it, so if anyone can't answer my questions, but does have a good source I can look at, that would be nice, too.

like image 467
Daniel Ward Avatar asked Sep 09 '11 12:09

Daniel Ward


People also ask

Can you create a new file extension?

To create your own file extension all you need to do is to place the desired extension after the last period in the filename. 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.

How do you create a new file and write to a file in Java?

Example 1: Java Program to Create a File java is equivalent to // currentdirectory/JavaFile. java File file = new File("JavaFile. java"); We then use the createNewFile() method of the File class to create new file to the specified path.


1 Answers

Java Web Start is not only a freely available installer that comes from Oracle, but it will also register an apps. interest in file types. See the File service demo. for an example.

like image 161
Andrew Thompson Avatar answered Nov 02 '22 05:11

Andrew Thompson