[英]Runtime.exec() command with utf-8 characters
我正在尝试执行包含波兰语字符的Runtime.getRuntime()。exec()命令。 命令从第一个波兰字母中切出。 我得到的不是波兰字母,而是“?”。
如何设置正确的编码以正确执行此命令?
我正在使用的命令:execCommand(“ php / home / script / url param1 param2 param3)
execCommand看起来像:
private String execCommand(String command)
{
String output="";
try
{
Process proc = Runtime.getRuntime().exec(command);
BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
try
{
proc.waitFor();
}
catch(InterruptedException e)
{
output=e.getMessage();
}
while(read.ready())
{
output=read.readLine();
}
}
catch(IOException e)
{
output=e.getMessage();
}
return output;
}
您可以尝试以下方法:
String command = URLEncoder.encode("<your command>", "utf-8");
然后,您可以尝试通过Runtime.exec
运行它
您还可以检查您的JDK是否真正支持:
Charset.forName("UTF-8")
如果由于任何原因失败,那么您的JDK中可能存在错误/未配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.