我刚刚发现 VFS 作为访问 sftp 的一种方式。似乎有效,但所有示例都假定一个本地文件;相反,我将数据保存在内存中。我只看到一个方法copyFrom(FileObject),没有接受流或缓冲区的重载......所以我尝试了ram,因为它听起来大致正确(一些文档不会受到伤害,但我不能很好)并且以下测试成功. 复制到 sftp FileObject 也可以。
问题。它提供以下输出: INFO:使用“C:\Users\myname\AppData\Local\Temp\vfs_cache”作为临时文件存储。
- 它实际上是在写一个临时文件吗?这就是我试图避免的(由于运行这个东西的 Unix 服务器上潜在的权限/并发问题)。如果是这样,我如何完全在内存中完成它?
// try to copy a string from memory into a FileObject
public class VFSTest {
public static void main(String[] args) throws IOException {
String hello = "Hello, World!";
FileObject ram = VFS.getManager().resolveFile("ram:/tmp");
OutputStream os = ram.getContent().getOutputStream();
os.write(hello.getBytes());
ram.getContent().close();
FileObject local = VFS.getManager().resolveFile("C:\\foo.txt");
local.copyFrom(ram, Selectors.SELECT_SELF);
}
}