-1

I am working on a project that uses Huffman algorithm to compress files, and I am doing my project using Java, what I want is to create my own file extension say (.huff) for the compressed file, and when I right click a file if it has the (.huff) extension, I want to add a new option which decompresses it, I searched the web but I did not find anything useful. Any help would be appreciated.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
fareed
  • 19
  • 1
  • 5
  • 2
    What do you mean by "and when I right click it I want to add a new option which decompresses it" – Emax Mar 26 '18 at 14:12
  • 2
    Possible duplicate of [How can I add a context menu to the Windows Explorer for a Java application?](https://stackoverflow.com/questions/370114/how-can-i-add-a-context-menu-to-the-windows-explorer-for-a-java-application) – jrtapsell Mar 26 '18 at 14:15
  • @ jrtapsell I edited my question, maybe this is a better explanation – fareed Mar 26 '18 at 14:23
  • 2
    @fareed the linked question seems to be exactly what you are looking for ie. it explains how to add a right click action for a specific file extension, could you explain where it falls short? – puhlen Mar 26 '18 at 14:34
  • @puhlen it does not answer my whole question just the part concerned with adding a right click action which it answers perfectly – fareed Mar 26 '18 at 14:40

2 Answers2

0

To set the file extension just use one of the String methods like append(".yourExtension") (append it to the filename) and set as filename. Simple as that.

String filename = filename.append(extension);

To decompress the compressed file, I suggest you write a metod to which you provide a path to file as argument, check if the file extension is correct and then in another method you decompress this file.

augenss
  • 71
  • 10
  • This answer does not describe how to add the custom tool to the context menu "_when I right click it I want to add a new option which decompresses it_" – takendarkk Mar 26 '18 at 14:18
  • You're right, but from what I understood from the question, fareed was asking about a few things. But maybe I understood wrong. _"what I want is to create my own file extension for the compressed file"_ – augenss Mar 26 '18 at 14:19
0

There is nothing special about a file extension, it's just a part of the file name. To create a .huff file extension, just add .huff to the end of the file name.

To add the windows context menu, that's explained in the question linked in the comments How can I add a context menu to the Windows Explorer for a Java application?

I would recommend creating a batch script that will launch your program taking in the file to decompress as an argument.

Something similar to:

@echo off
java -cp <path-to-jar> <decompression main class> %1

Adding in any other setup or program arguments you need. Then a registry entry might look like.

HKEY_CLASSES_ROOT\.huff\shell\Decompress huffman encoded file\command
"<path to batch file>" "%1"
puhlen
  • 8,400
  • 1
  • 16
  • 31