Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从Spring中的URL下载_Java_Spring_Download - Fatal编程技术网

Java 从Spring中的URL下载

Java 从Spring中的URL下载,java,spring,download,Java,Spring,Download,我希望,通过将文件的URL(文件可以是图像、Xhtml或Css)粘贴到JSP格式中,可以从internet下载并在本地保存。您能帮我吗?您可以使用此选项在浏览器中打开URL并保存到文件位置。 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_MO

我希望,通过将文件的URL(文件可以是图像、Xhtml或Css)粘贴到JSP格式中,可以从internet下载并在本地保存。您能帮我吗?

您可以使用此选项在浏览器中打开URL并保存到文件位置。
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();
%>