我正在编写一个程序,客户端将调用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