备案的网站程序上传,网站域名去哪买,深圳创业贷款条件申请及流程,做网站编辑如何写好一篇新闻java缓存读取图片老师布置了任务#xff0c;需要把数据库中的图片一缓存的形式读出#xff0c;不要说什么数据库中路劲#xff0c;图片整体较大#xff0c;在给别人使用时不现实。关键代码#xff1a;for(int i0;i1;i){downloadDB(bi);pm[i]new paintimage(bi);}publi…java缓存读取图片老师布置了任务需要把数据库中的图片一缓存的形式读出不要说什么数据库中路劲图片整体较大在给别人使用时不现实。关键代码for(int i0;i1;i){downloadDB(bi);pm[i]new paintimage(bi);}public void downloadDB(BufferedImage bi){try{/* String sc:\\downloadDB\\i.png;File filenew File(s);FileOutputStream fosnew FileOutputStream(file);*/InputStream innull;String urljdbc:mysql://192.168.**.***:3306/de;Class.forName(com.mysql.jdbc.Driver);Connection conDriverManager.getConnection(url,root,***);String sqlselect * from campusimage;Statement stcon.createStatement();ResultSet rsst.executeQuery(sql);for(int j0;j1;j)rs.next();int m;if(rs.next())inrs.getBinaryStream(1);/*while((min.read())!-1)fos.write(m);*/BufferedInputStream isnew BufferedInputStream(in);biImageIO.read(is);System.out.println(00000000000);rs.close();st.close();con.close();}catch(Exception e){e.printStackTrace();}}class paintimage extends JPanel{//ImageIcon iconnull;Image imanull;paintimage(BufferedImage bi){/*String s1c:\\downloadDB\\i.png;iconnew ImageIcon(s1);imaicon.getImage();*/ima(Image)bi;setBounds(0,0,700,600);System.out.println(1111111111);}public void paint(Graphics g){g.drawImage(ima,0,0,700,600,null);System.out.println(2222222222);}}求指教我会出的是空白图。java缓存图片数据库mysql分享到------解决方案--------------------如果读出来是16进制字符串的话16进制字符串-》byte数组-》流-》文件public class ImgHelper {public static void getImg(String hexString) {byte[] b ByteHelper.hexStringToBytes(hexString);InputStream is ByteHelper.byte2Input(b);createFile(is, new File(D://pp.jpg));}//生成图像文件public static void createFile(InputStream is, File targetFile) {BufferedInputStream inBuff null;BufferedOutputStream outBuff null;try {// 新建文件输入流并对它进行缓冲inBuff new BufferedInputStream(is);// 新建文件输出流并对它进行缓冲try {outBuff new BufferedOutputStream(new FileOutputStream(targetFile));// 缓冲数组byte[] b new byte[1024 * 5];int len;while ((len inBuff.read(b)) ! -1) {outBuff.write(b, 0, len);}// 刷新此缓冲的输出流outBuff.flush();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}} finally {// 关闭流try {if (inBuff ! null)inBuff.close();if (outBuff ! null)outBuff.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}public class ByteHelper {public static byte[] hexStringToBytes(String hexString) {if (hexString null------解决方案--------------------hexString.equals()) {return null;}hexString hexString.toUpperCase();int length hexString.length() / 2;char[] hexChars hexString.toCharArray();byte[] d new byte[length];for (int i 0; i int pos i * 2;