Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Passing command line unicode argument to Java code

PankajAgrawalOct 5 2011 — edited Oct 7 2011
I have to pass command line argument which is Japanese to Java main method. If I type Unicode characters on command-line window, it displays '?????' which is OK, but the value passed to java program is also '?????'. How do I get the correct value of argument passed by the command window? Below is sample program which writes to a file the value supplied by command line argument.

public static void main(String[] args) {
String input = args[0];
try {
String filePath = "C:/Temp/abc.txt";
File file = new File(filePath);
OutputStream out = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
InputStream is = new ByteArrayInputStream(input.getBytes());
while ((len = is.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 4 2011
Added on Oct 5 2011
3 comments
950 views