Java 通过SFTP Jsch将文件从Windows上载到Unix错误,目录路径为空值

Java 通过SFTP Jsch将文件从Windows上载到Unix错误,目录路径为空值,java,file-upload,sftp,jsch,Java,File Upload,Sftp,Jsch,我正在使用JSch通过sftp上传文件 im正在将文件从windows上载到unix服务器 上传即时通讯时使用 ChannelSFTP.put(file) 因此: File file = FiletoPath; sftp.put(new FileInputStream(file), file.getName()); 但是,由于getName()将返回文件名或绝对路径,因此这将显示为: \\something\something\Documents$\something\something\m

我正在使用JSch通过sftp上传文件

im正在将文件从windows上载到unix服务器

上传即时通讯时使用

ChannelSFTP.put(file)
因此:

File file = FiletoPath;
sftp.put(new FileInputStream(file), file.getName());
但是,由于getName()将返回文件名或绝对路径,因此这将显示为:

\\something\something\Documents$\something\something\myfilename.txt

当我尝试拆分时,它会出错

String[] split = file.getName().split("\\");
sftp.put(new FileInputStream(file), split[split.length-1]);
我不知道。如何解决这个问题?

我已经解决了

基本上是由于

\\此反斜杠将使它们具有空值并引发异常

我使用org.google.guava.Splitter.jar: 在线下载

下面是我的代码片段:

//Declaration of JSch Connection session,
//channel and ChannelSftp
//filetype: MultiPartFile

String filename = file.getName();
Iterables<String> itr = Splitter.on("\\").trimResults().omitEmptyStrings().split(filename);
String[] split = Iterables.toArray(itr);

ChannelSftp.put:

//Change Directory to upload the file:
String uploadDirectoryPath = "/usr/name/profile/toStorePath/files/";

try{
     csftp.cd(uploadDirectoryPath);
     csftp.put(file.getInputStream(), split[split.length-1]);
} catch(SftpException | IOException e){
    e.printStackTrace();
}
//JSch连接会话的声明,
//通道和通道SFTP
//文件类型:MultiPartFile
字符串文件名=file.getName();
Iterables itr=Splitter.on(“\\”).trimResults().omitEmptyStrings().split(文件名);
String[]split=Iterables.toArray(itr);
通道SFTP.put:
//更改目录以上载文件:
字符串uploadDirectoryPath=“/usr/name/profile/toStorePath/files/”;
试一试{
cd(uploadDirectoryPath);
csftp.put(file.getInputStream(),split[split.length-1]);
}捕获(SftpException | IOE异常){
e、 printStackTrace();
}

您面临的错误是什么?当它上载到服务器时,将其另存为\something\something\Documents$\something\something\myfilename.txt而不是myfilename.txt。如何使用?