0

i want to open .chm help file when click on Help button on swing window. how should i do?

if(e.getActionCommand() == "Help" ){
        Runtime run = Runtime.getRuntime();
        try
        {
        Process child = Runtime.getRuntime().exec("F:\OfficeCommunicatorClient\src\resources\User Account HelpNew.chm\");
        }
        catch (Exception ex)
        {
        ex.printStackTrace();
        System.out.println(ex.getMessage());
        }

    }
Vinay
  • 347
  • 1
  • 7
  • 16
  • try this http://forums.sureshkumar.net/java-technologies/9438-opening-help-chm-files-java.html – PresleyDias Mar 19 '12 at 09:35
  • probably not an error here, but Strings should be compared using `equals` not `==`. And much better IMO is to use a constant for the ActionCommand (`CMD_HELP = "Help"`). – user85421 Mar 19 '12 at 09:47
  • 1) `src\resources\User Account HelpNew.chm` The combination of `src` & `resources` makes me think this is an application resource that will arrive at the computer of the end user in a Jar. If so, it cannot be accessed by `File` at that point, only `URL`. 2) Using `exec` is obviously platform dependent, what do you intend to do for users of *nix & OS X? 3) There are a number of things wrong with that invocation of `exec`, but I do not think it is a viable approach in any case. – Andrew Thompson Mar 19 '12 at 09:54

2 Answers2

0

First of all remove last '\'. It suggests it is a directory instead of a file.

Secondly you should use either double '\' or single '/': F:\\OfficeCommunicatorClient\\src\\resources\\User Account HelpNew.chm or F:/OfficeCommunicatorClient/src/resources/User Account HelpNew.chm

@edit It seems that the help cannot be run itself. Use hh.exe to open the help file. Moreover the file must be inside "", so the string should look like: "hh.exe \"F:/OfficeCommunicatorClient/src/resources/User Account HelpNew.chm\""

To get the path you are relative to, use this sample code:

File f = new File(".");
System.out.println(f.getAbsolutePath());
anakkin
  • 731
  • 1
  • 6
  • 21
  • ya i have done that but its still not opening. its shoeing following error: Cannot run program ""F:\OfficeCommunicatorClient\src\resources\User": CreateProcess error=193, %1 is not a valid Win32 application – Vinay Mar 19 '12 at 09:36
  • remove the spaces in the name of your .chm file. – bmkorkut Mar 19 '12 at 09:42
  • how can i get it working in executable jar file. because when i create it there may be vary file path. i dont want absolute path here.. – Vinay Mar 19 '12 at 09:52
0

try this from this site codeproject

 Runtime.getRuntime().exec("hh.exe F:/OfficeCommunicatorClient/src/resources/User Account HelpNew.chm");

check this also open chm file in java

Community
  • 1
  • 1
PresleyDias
  • 3,657
  • 6
  • 36
  • 62
  • how can i get it working in executable jar file. because when i create it there may be vary file path. i dont want absolute path here. – Vinay Mar 19 '12 at 09:58
  • @Vinay : for that please try this question http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file – PresleyDias Mar 19 '12 at 10:13
  • Also this http://stackoverflow.com/questions/227486/find-where-java-class-is-loaded-from – PresleyDias Mar 19 '12 at 10:13
  • when i tried for this private String path = ClientLoginUI.class.getResource("/resources/UserAccountHelpNew.chm").getPath(); i got error message that "file could not open" – Vinay Mar 19 '12 at 10:32
  • try this for the path http://stackoverflow.com/questions/218061/get-the-applications-path – PresleyDias Mar 19 '12 at 11:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9073/discussion-between-vinay-and-presleydias) – Vinay Mar 20 '12 at 08:03