我收到了來自 Web 服務請求的響應,我可以在控制臺上打印該響應。我想將此響應寫入 json 文件。我嘗試使用 buffereWriter 但它沒有寫入。String cwd = System.getProperty("user.dir");buffereWriter writer = new buffereWriter (new File writer(cwd + "filepath"));Writer.write(response);// This response is being currently displayed in the console correctly.沒有錯誤或異常,但內容未寫入文件。
1 回答
慕斯709654
TA貢獻1840條經驗 獲得超5個贊
你可以使用FileWriter它。還有一個try block資源可以保證您的文件將被關閉。
try(FileWriter fw = new FileWriter(cwd + "filepath")){
fw.write(response); //I guess the response is a String.
}catch(Exception ignored){}
添加回答
舉報
0/150
提交
取消
