嗨我已經嘗試了以下java代碼,如果我將它們用作java應用程序,但是當我在我的servlet頁面中使用相同的代碼時,它們不工作意味着我無法下載文件。請建議我應該做什麼修改,以便我可以使用Servlet下載文件。使用servlet下載文件
a。
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://169.254.174.150:8084/WebApplication1/files/check.txt").openStream());
File f1 = new File("D:\\a.txt");
java.io.FileOutputStream fos = new java.io.FileOutputStream(f1);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte data[] = new byte[1024];
while (in.read(data, 0, 1024) >= 0) {
bout.write(data);
}
bout.close();
in.close();
}
b。 http://www.javabeat.net/examples/2012/04/13/download-file-from-http-https-server-using-java/