How to run external file in java program?

J

jacekfoo

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.
 
S

Soren Kuula

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
 
J

jacekfoo

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
 
S

Soren Kuula

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
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

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
 
J

jb

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top