This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

file type association with my java program

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there.
i've created my own notepad application using java.
now, i want all files with .txt extension use my program as default viewer/editor.

is there a way i can programmatically associate .txt extension with my app?

thanks in advance.
 
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only by modifying the registry (Windows) or the appropriate configuration files (Linux, Mac OS) from your program.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so this means that it cant be done programatically?

thanks for this info mr. rob.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jhedzkie Skies wrote:so this means that it cant be done programatically?


That's not what Rob wrote...
 
Rob Spoor
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be done, but it's going to require a bit of extra work. First of all, you need to know where and how the file association is stored. Then you need to know how to create / modify associations. And you may also want to have an undo function that allows you to restore the previous file association, in case someone wants to uninstall your application.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see. i think i'll try to learn about associations first. thanks for the tip.
 
Ranch Hand
Posts: 35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if its windows - this is how i would do this

Have a customized installer.

when installing ask user if you want to associate .txt with your program. to start with you can make a new extn like .t1 and use that

most installers have the API to call to associate an extension with a program - some of the freeware ones too.

Your program will have to a .bat to start with
which will call java command line and pass the text file name to it

java.exe com.your_package.your_main_class %*

for this to work java should be installed and be in windows PATH var

else need to add the java home path ...
c:\java_home_path\bin\java.exe com.your_package.your_main_class %*

one level deeper would be to make a custom java launcher exe but that will be in c++ - check where java is installed and then launch it with correct params
 
What's that smell? I think this tiny ad may have stepped in something.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic