我正在編寫一個程序,客戶端將調用POST方法傳遞一個字符串,在POST方法內,它會將該字符串寫入位於EC2上的文件。但我被困在EC2上創建一個文件並將內容寫入它。到目前爲止,我有一個像這樣的POST方法:寫入位於EC2上的文件
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Response postEntry(MyEntry myEntry) throws URISyntaxException {
try {
FileWriter fw = new FileWriter("\\\\my-instance-public-ip-address\\Desktop\\data.txt", true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(myEntry.toString());
bw.close();
fw.close();
} catch (Exception e) {
System.err.println("Failed to insert : " + e.getCause());
e.printStackTrace();
}
String result = "Entry written: " + myEntry.toString();
return Response.status(201).entity(result).build();
}
我做錯了嗎?文件位置是否錯誤? (該程序運行時沒有錯誤,但沒有提交文件)。任何幫助將不勝感激。
爲什麼你沒有在操作系統中用EC2 Instance標記你的問題? – 2017-10-14 23:36:32