Results 1 to 6 of 6
  1. #1
    Pesch is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default Opening Text Files with Default System Editor

    Is there a platform independent way to open a text file using the default system text editor?

    Barring that, how difficult would it be to set up some swing components to display text files? I have very little experience with GUI programming or Swing.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Pesch View Post
    Is there a platform independent way to open a text file using the default system text editor?
    First of all you have to find what is the default text editor is. I think on Windows it's Notepad. So you can use Runtime class, with Notepad.exe. For Linux and UNIX systems there is a common way to do it. Just Google it, I'm not remember what it is. Anyway you have to use the Runtime class there too.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If you have 1.6 or later, read the API docs for the Desktop class and it's open method.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    It is dependant on the OS and on how a user has tailored his system. I'm on XP and I've set Wordpad to open when I click on a .txt file.
    In windows there is an OS command that will lookup the default command to use when opening a file. However I think its different on different versions of windows. For some it's CMD and for others its COMMAND.

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Norm View Post
    For some it's CMD and for others its COMMAND.
    I thought it was "COMMND" but that was long ago.

    Its been CMD in Windows 32 bit always. From NT 3.1 on.

    If you are still running Win16 (windows 95, Win98, WindowsME) then its still COMMAND (or COMMND) but no one should be using those things. They are from last century.

    Back on topic, the reason that java 1.6 has the Desktop stuff is that without it, you can't do it transparently without all sorts of OS specific voodoo

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Where does Java find the "user-default' programs?

    I just tried the DesktopDemo program from the Java Tutorial and find that it does NOT use my defauts. I've tailored my system changing MS's defaults to what I like. For example, DC on a .html file starts Firefox. DC on a .txt file starts Wordpad.
    In the DesktopDemo program, it started IE for a .html file and Notepad for a .txt file. Those are NOT my defaults.

    Where does the JVM look to find the "user-default" programs? I would assume on Windows it'd look in the registry. It obviously doesn't use the same path as a user can to set the defaults: Tools|Folder Options|File Types|Registered Filetypes ...

    Thanks,
    Norm

Similar Threads

  1. Default/System Date Format Pattern?
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 1
    Last Post: 10-05-2008, 07:34 AM
  2. opening jar files on pc prepared by mac
    By willemjav in forum Advanced Java
    Replies: 42
    Last Post: 09-27-2008, 05:53 PM
  3. Invoking the system text editor on autoexec.bat
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:32 PM
  4. SWT Text Editor
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •