3

プロパティを変更した後、プロパティを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"); 
} 
4

1 に答える 1

12

確かに - 最も簡単な方法は、 を作成しByteArrayOutputStream、その中に保存してByteArrayInputStreamから、結果の周りに を作成することです:

ByteArrayOutputStream output = new ByteArrayOutputStream();
ssProperties.store(output, null);
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
sftpConnection.upload(input, fileDirectory);
于 2012-08-09T20:25:20.987 に答える