[英]Jar file not accepting huge string in java
What is the best way of passing a string (arg1 in case of code below) with about 800K characters (yes, that's a huge number) to a java jar. 将具有约800K个字符(是的,这是一个巨大的数字)的字符串(在下面的代码中为arg1)传递给Java jar的最佳方法是什么。 Following is the code I am using to invoke the jar file:
以下是我用来调用jar文件的代码:
p = Runtime.getRuntime().exec(jrePath+"/bin/java -jar C:/folder/myjar.jar methodName" + arg1);
ALternately, how can I create a jar file to accept one String
input and one byte[]
input in main{ in void main(String args[])
} 或者,如何创建一个jar文件以在
void main(String args[])
main {中接受一个String
输入和一个byte[]
输入
Or any other ideas? 还是其他想法? The requirement is to somehow pass the huge
String
/ byte[]
of String
to a java jar file that I am creating 该要求是巨大的某种方式传递
String
/ byte[]
的String
来,我创建Java jar文件
As mentioned in this question , there is a maximum argument length set by the operating system. 如本问题所述,操作系统设置了最大参数长度。 Seeing as this argument is
800K
characters, its fairly safe to say that you have exceeded this max value on most computers. 鉴于此参数为
800K
字符,因此可以肯定地说,您已在大多数计算机上超过了此最大值。 To get around this, you can write arg1
to a temp file using the built in API: 为了解决这个问题,您可以使用内置的API将
arg1
写入临时文件:
final File temp;
try {
temp = File.createTempFile("temp-string", ".tmp");
} catch (final IOException e){
//TODO handle error
return;
}
try (final BufferedWriter writer = new BufferedWriter(new FileWriter(temp))) {
writer.write(arg1);
} catch (final IOException e){
//TODO handle error
return;
}
try {
// run process and wait for completion
final Process process = Runtime.getRuntime().exec(
jrePath + "/bin/java -jar C:/folder/myjar.jar methodName " +
temp.getAbsolutePath());
final int exitCode = process.waitFor();
if (exitCode != 0) {
//TODO handle error
}
} catch (final IOException | InterruptedException e){
//TODO handle error
return;
}
if (!file.delete()) {
//TODO handle error
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.