URL url = new URL("http://localhost:8080/Work/images/abt.jpg");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n=0;
while (-1!=(n=in.read(buf)))
{
out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response1 = out.toByteArray();
FileOutputStream fos = new FileOutputStream("C://abt.jpg");
fos.write(response1);
fos.close();
in this code there is some error in last 3 lines
SEVERE: Servlet.service() for servlet ImageDownloadServlet threw exception java.io.FileNotFoundException: C:/abt.jpg (No such file or directory)
How can I solve it?
("C://abt.jpg");
try reversing the slashes
("C:\\abt.jpg");
I looked up a example link to a FOS to C drive example, and the demo had them the other way.
maybe try switching
C:/abt.jpg
toC:\\abt.jpg
Try using File.pathSeparator instead of slash.
this image will be in download folder