我希望通过将文件的URL(文件可以是图像,Xhtml或Css)粘贴到JSP的形式中,这可以从Internet下载并在本地保存。请你能帮帮我吗?
答案 0 :(得分:4)
you can use this to open URL in the browser and save into the file location.
<%
String site= contain the string(URL);
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
File file = new File("/Users/asdf.xml");
FileWriter fr = null;
BufferedWriter br = null;
URL url = new URL(site);
BufferedReader reader = new BufferedReader
(new InputStreamReader(url.openStream()));
fr = new FileWriter(file);
br = new BufferedWriter(fr);
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
br.write(line);
br.newLine();
}
reader.close();
br.close();
%>