Java - 从 SFTP 直接下载到内存,无需写入文件 [英] Java - download from SFTP directly to memory without ever writing to file

查看:289
本文介绍了Java - 从 SFTP 直接下载到内存,无需写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几天我一直在研究这个,但似乎找不到任何从 SFTP 服务器读取并将内容写入内存而不是文件的示例或文档.这让我思考这是否可能.我希望将从 SFTP 流下载的文件写入内存中的字节数组,然后在字节数组在内存中时使用它.这可能吗?

I have been researching this for the past couple days but cannot seem to find an example or documentation for anything that reads from an SFTP server and writes the contents to memory and not a file. It got me thinking if this is even possible. I was hoping to write the file downloaded from the SFTP stream to a byte array in memory and then work with that while the byte array was in memory. Is this possible?

推荐答案

最常见的 Java SFTP 库,JSch,允许这样做.

The most common Java SFTP library, the JSch, allows this.

使用 ChannelSftp.get 方法,返回InputStream.

基本的一种是:

public InputStream get(String src)

这篇关于Java - 从 SFTP 直接下载到内存,无需写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆