java远程创建文件_spring SFTP从byte []远程创建文件

如何在byte []中创建远程目录中的文件,因为PollableChannel中有send()方法 . 从下面的代码能够发送文件到远程,但它在本地机器上创建一个文件 . 如何避免在本地机器上创建文件?

PollableChannel remoteFileChannel = context.getBean("outputChannel", PollableChannel.class);

Message sendFile = MessageBuilder.withPayload("hi how are you".getBytes()).build();

remoteFileChannel.send(sendFile);

spring sftp配置:

class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"

p:host="${sftp.host}"

p:port="${sftp.port}"

p:user="${sftp.username}"

p:password="${sftp.password}"

p:allowUnknownKeys="${sftp.allowUnknownKeys}" />

session-factory="sftpSessionFactory"

channel="outputChannel"

charset="UTF-8"

remote-directory="${sftp.remotedir}"

remote-filename-generator="randomFileNameGenerator" />

如何创建一个具有随机名称的文件并将字节写入其中?

我试过自定义文件名生成器类:

@Component("randomFileNameGenerator")

public class RandomFileNameGenerator implements FileNameGenerator {

@Override

public String generateFileName(Message> msg) {

long number = (long) Math.floor(Math.random() * 90000000L) + 1000000L;

String fileName = String.format("%d.txt", number);

return fileName;

}

}

如果文件名未设置,则创建名称为“adas-asdfsadf-545sadf.msg”的文件 . 任何人都可以指出我做错了什么

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值