我尝试从服务器获取txt文件并向其写入一些文本。但似乎我使用的方法并不起作用。
<intercept-url pattern="/savePhoto**" access="hasRole('VIEW')" method="POST"/>
我这样运行:
public static void writeFile(String urls, String text) throws Exception {
String string = URLEncoder.encode(text, "UTF-8");
URL url = new URL(urls);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write(string);
out.append("a");
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();
}
请告诉我我做错了什么。请帮我。先感谢您! :)