How to run external file in java program?

Discussion in 'Java' started by jacekfoo@gmail.com, Aug 23, 2006.

  1. Guest

    Main reason I need this facility is to convert .properties file from
    UTF-16 to ISO-8859-1. And I created a very simple program to do this.
    Is searches current dir for any files without an extension and then
    calls:
    Runtime.getRuntime().exec(/*Path to native2ascii*/ + "native2ascii.exe"
    + " " + Command).waitFor(). Where command is string containing
    -encoding UTF-16 sourcefile outputfile.
    And that command does nothing :(. Can you find error.
    , Aug 23, 2006
    #1
    1. Advertising

  2. Soren Kuula Guest

    wrote:
    > Main reason I need this facility is to convert .properties file from
    > UTF-16 to ISO-8859-1. And I created a very simple program to do this.
    > Is searches current dir for any files without an extension and then
    > calls:
    > Runtime.getRuntime().exec(/*Path to native2ascii*/ + "native2ascii.exe"
    > + " " + Command).waitFor(). Where command is string containing
    > -encoding UTF-16 sourcefile outputfile


    Consider doing the re-coding internally in your Java program instead of
    using an external program. I think it will be much less trouble (with
    things like the character encoding on streams between your Java program
    and the external one...)..

    Open a Reader with the source encoding, read the whole file into a
    String or StringBuilder. Then, open a Writer with the target enocoding
    and write the string back.

    Søren
    Soren Kuula, Aug 23, 2006
    #2
    1. Advertising

  3. Guest


    > Open a Reader with the source encoding, read the whole file into a
    > String or StringBuilder. Then, open a Writer with the target enocoding
    > and write the string back.


    Didn't do tha job. Id would be good if I converted between UTF-16 and
    UTF-8, or anything else. Point is that ISO-8859-1 doesnt support that
    chars i want in my files. Native2ascii conwerts them to unicode escape
    chars.
    ie. (hope servers don't mess it)
    Source: alejezuzzy
    native2ascii output: \u0163\u02d9 B j e z u z | y
    HandConvertedOutput: ???je?uz?y
    , Aug 23, 2006
    #3
  4. Soren Kuula Guest

    wrote:
    >>Open a Reader with the source encoding, read the whole file into a
    >>String or StringBuilder. Then, open a Writer with the target enocoding
    >>and write the string back.

    >
    >
    > Didn't do tha job. Id would be good if I converted between UTF-16 and
    > UTF-8, or anything else. Point is that ISO-8859-1 doesnt support that
    > chars i want in my files. Native2ascii conwerts them to unicode escape
    > chars.


    Aah, got it.

    If it were me, I would probably just scan through the (properly decoded)
    string for chars > 255, and replace then by the escaped value then...
    the numerical value of the char is the value you want to print as hex .
    with a & in front of it and a ; at the tail.

    But OK, if you insist on the external program (after all it works),
    sorry I don't know how to make it work reliably from Java.

    Søren
    Soren Kuula, Aug 24, 2006
    #4
  5. wrote:
    > Main reason I need this facility is to convert .properties file from
    > UTF-16 to ISO-8859-1. And I created a very simple program to do this.
    > Is searches current dir for any files without an extension and then
    > calls:
    > Runtime.getRuntime().exec(/*Path to native2ascii*/ + "native2ascii.exe"
    > + " " + Command).waitFor(). Where command is string containing
    > -encoding UTF-16 sourcefile outputfile.
    > And that command does nothing :(. Can you find error.


    The correct form is:

    Runtime.getRuntime().exec(new String[] { /*Path to native2ascii*/ +
    "native2ascii.exe", "-encoding", "UTF-16", sourcefile,
    outputfile}).waitFor()

    The one used accidentally works on window,s but it will fail on Linux.

    I would suggest you try and get the output from the program:

    Process p = Runtime.getRuntime().exec("...");
    BufferedReader br = new BufferedReader(new
    InputStreamReader(p.getInputStream()));
    String line;
    while((line = br.readLine()) != null) {
    System.out.println(line);
    }

    and see if there are any clues in the output.

    Typical it is a directory problem.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Aug 24, 2006
    #5
  6. jb Guest


    > I would suggest you try and get the output from the program:
    >
    > Process p = Runtime.getRuntime().exec("...");
    > BufferedReader br = new BufferedReader(new
    > InputStreamReader(p.getInputStream()));
    > String line;
    > while((line = br.readLine()) != null) {
    > System.out.println(line);
    > }


    OK thanks. I have found a different solution - ResourceBoundle Editor
    plugin in Eclipse. But I'll remember that hint next time I'll need to
    run some program.
    jb, Aug 24, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dmitry Duginov

    Run external program during BUILD?

    Dmitry Duginov, May 2, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    700
    Chris R. Timmons
    May 2, 2005
  2. Tamer Higazi
    Replies:
    2
    Views:
    383
    Thomas M.
    Jul 22, 2003
  3. ash
    Replies:
    5
    Views:
    297
  4. Brant Sears

    Trying to run an external program

    Brant Sears, Sep 20, 2006, in forum: Python
    Replies:
    4
    Views:
    310
    Larry Bates
    Sep 21, 2006
  5. Lad
    Replies:
    4
    Views:
    436
    Gabriel Genellina
    Jan 13, 2007
Loading...

Share This Page