【发布时间】:2018-04-25 03:23:11
【问题描述】:
这是我遇到的错误
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at TrfFiles2Dev.main(TrfFiles2Dev.java:55
这是我正在处理的代码
public void send (String fileName) {
String SFTPHOST = "";
int SFTPPORT = 22;
String SFTPUSER = "";
String SFTPPASS = "";
String SFTPWORKINGDIR = "";
Logger log = Logger.getLogger(TrfFiles2Dev.class.getName() );
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
System.out.println("preparing the host information for sftp.");
try {
JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
System.out.println("Host connected.");
channel = session.openChannel("sftp");
channel.connect();
System.out.println("sftp channel opened and connected.");
channelSftp = (ChannelSftp) channel;
channelSftp.cd(SFTPWORKINGDIR);
File f = new File(fileName);
channelSftp.put(new FileInputStream(f), f.getName());
log.info("File transfered successfully to host.");
} catch (Exception ex) {
System.out.println("Exception found while tranfer the response.");
}
finally{
channelSftp.exit();
System.out.println("sftp Channel exited.");
channel.disconnect();
System.out.println("Channel disconnected.");
session.disconnect();
System.out.println("Host Session disconnected.");
}
}
public static void main(String[] args) {
TrfFiles2Dev trfFiles2Dev = new TrfFiles2Dev();
trfFiles2Dev.send(args[0]);
} }
提前感谢您的帮助。我不想为我完成这件事,我只是卡住了,需要帮助找到我的方式。
以及如何将文件从我的服务器传输到其他服务器?
【问题讨论】:
-
TrfFiles2Dev 中的第 55 行是什么
-
哪一行出错了?
-
你能分享这门课吗?
-
基本上这个错误告诉你在第 55 行访问的数组在你尝试使用的数组大小内没有索引。
-
可能 55 是 trfFiles2Dev.send(args[0]);,这意味着你在运行程序时没有指定任何命令行参数