将属性转换为输入流?

Ale*_*lex 2 java sftp properties

在我们修改它之后,是否可以将Properties转换为InputStream.

这里有一些代码来澄清这个问题:

sftpConnection = new connectSFTP(host, user, pass, port);
Properties ssProperties = new Properties();
InputStream in = null;
try{
    in = sftpConnection.download(fileName, fileDirectory);
    ssProperties.load(in);
    //System.out.println("File Found");
    ssProperties.setProperty(key, value);
    sftpConnection.upload(<<Need the new InputStream here>>, fileDirectory);
    in.close();     
}
catch(Exception ex)
{
System.out.println("File Not Found"); 
} 
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 10

当然 - 最简单的方法是创建一个ByteArrayOutputStream,保存到那个,然后创建一个ByteArrayInputStream结果:

ByteArrayOutputStream output = new ByteArrayOutputStream();
ssProperties.store(output, null);
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
sftpConnection.upload(input, fileDirectory);
Run Code Online (Sandbox Code Playgroud)