In server development, when the client needs to load the image files sent by the server, the server needs to provide a program for downloading images.
The code for downloading the image tool is as follows:
Import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. ioexception; import Java. io. inputstream; public class downloadimageutil {public static byte [] getpicbytes (string goodspic) {string picurl = "D: \ tomcat6.0 \ apache-Tomcat-6.0.39 \ webapps \ usedmallminaserver \ images \ goodsphotos \ "+ goodspic; // create a file picfile = new file (picurl); // use the file stream to read the image file inputstream is; byte [] picbytes = NULL; try {is = new fileinputstream (picfile); int Len = (INT) picfile. length (); // create a byte array picbytes = new byte [Len]; int offset = 0; int numread = 0; // convert the file flow into a byte array while (offset <picbytes. length & (numread = is. read (picbytes, offset, Len)> = 0) {Offset + = numread;} catch (filenotfoundexception e) {e. printstacktrace ();} catch (ioexception e) {e. printstacktrace ();} return picbytes ;}}