我正在尝试使用jcraft将json对象从java窗口发送到Unix。当数组大小为65时,它工作正常但是当我添加一个数组元素时,它会抛出com.jcraft.jsch.JSchException引起:java.lang.ArrayIndexOutOfBoundsException。 关注方法如下: -
public void appendData(String user, String pwd, String host, Integer port,
String str_Content, String usrHome, String destDir, String fileName) {
int statusCode = -5;
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(pwd);
session.setConfig(config);
session.connect();
System.err.println("Connected");
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("echo " + "\'" + str_Content
+ "\'" + " >> " + usrHome + destDir + "/" + fileName);
channel.connect();// ---------This line gives error -------
channel.disconnect();
session.disconnect();
System.out.println("Waiting for next hit...");
}
catch (JSchException e) {
e.printStackTrace();
}
}// appendData
堆栈跟踪是: -
com.jcraft.jsch.JSchException: ChannelExec
at com.jcraft.jsch.ChannelExec.start(ChannelExec.java:48)
at com.jcraft.jsch.Channel.connect(Channel.java:200)
at com.jcraft.jsch.Channel.connect(Channel.java:144)
at com.telus.util.KudooUtility.appendData(KudooUtility.java:80)
at com.telus.util.KudooTimerExecutor.run(KudooTimerExecutor.java:52)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.jcraft.jsch.Buffer.putByte(Buffer.java:55)
at com.jcraft.jsch.Buffer.putString(Buffer.java:63)
at com.jcraft.jsch.Buffer.putString(Buffer.java:59)
at com.jcraft.jsch.RequestExec.request(RequestExec.java:54)
at com.jcraft.jsch.ChannelExec.start(ChannelExec.java:43)
... 13 more