2017-01-23 525 views
2

我有一个Properties对象。我需要通过HTTP POST将其内容作为文件发送。Java属性对象到ContentBody

Properties类允许我写入文件,但我试图避免实际写入文件系统,因为我已经有了我需要的内存并且只是想通过网络发送它。

MultipartEntityBuilder类允许我提供ContentBody。什么是将我的Properties对象转换为ContentBody的最短路径?

回答

2

下面演示了如何将其写入到一个字符串,您可以使用POST。看看它是否有帮助。

public static void main(String[] args) { 
    Properties prop= new Properties(); 
    prop.put("aa", "ff"); 
    StringWriter sw = new StringWriter(); 
    prop.list(new PrintWriter(sw)); 
    System.out.println(sw.toString()); 
}