
示例为:读取图片为二进制流,并写入到其他图片中
static void testCopyImage(){ File source=new File("E:\\share\\Wallpaper\\Bliss.jpg"); File desk=new File("d:\\images"); if(!desk.exists()){ desk.mkdir(); } try { FileInputStream inputStream=new FileInputStream(source); FileOutputStream outputStream=new FileOutputStream(new File("d:/images/Bliss.jpg")); int ch=inputStream.read(); while(ch!=-1){ outputStream.write(ch); ch=inputStream.read(); } inputStream.close(); outputStream.close(); System.out.println("图片复制成功!"); } catch (FileNotFoundException e) { System.out.println("文件不存在:"+e.getMessage()); } catch (IOException e) { System.out.println("文件读取错误:"+e.getMessage()); } }
创建一个虚拟解密文件设备,传递给该设备的参数就是它的真实物理地址,多媒体那边像正常文件操作一样。这个虚拟解密设备的驱动则负责解码。注意,你使用的加密方式必须是流加密,否则视频播放会有问题。
上传图片可以用java,过tomcat
下载图片不用java,不过tomcat。图片是静态资源,不需要经过java的动态解析,java也不擅长。可以用nginx来做静态文件服务器,如果要更高效率的可以使用CDN。
如果图片量不多,直接存磁盘;如果是海量图片,就需要存储到单独的分布式文件系统,如FastDFS、TFS、MogileFS。