Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

How to run external file in java program?

Thread view: 
jacekfoo@gmail.com - 23 Aug 2006 13:14 GMT
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.
Soren Kuula - 23 Aug 2006 13:30 GMT
> 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.
[quoted text clipped - 3 lines]
> + " " + 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
jacekfoo@gmail.com - 23 Aug 2006 15:16 GMT
> 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
Soren Kuula - 24 Aug 2006 02:29 GMT
>>Open a Reader with the source encoding, read the whole file into a
>>String or StringBuilder. Then, open a Writer with the target enocoding
[quoted text clipped - 4 lines]
> 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
Arne Vajhøj - 24 Aug 2006 02:51 GMT
> 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.
[quoted text clipped - 4 lines]
> -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
jb - 24 Aug 2006 12:05 GMT
> I would suggest you try and get the output from the program:
>
[quoted text clipped - 5 lines]
>           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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.