图片上传的一个类 分享给大家
2011-08-11 19:43
477 查看
public class ImageUrlUtils { public static String getImageUrlByInputStream(ServletInputStream inputStream) throws IOException{ String urlFilePath = new String(); urlFilePath = "uploadpic/"; File direct = new File(filePath); String lstr = Long.toString(System.currentTimeMillis()); /*判断图片类型 start*/ int position=-1; byte[] buffer = new byte[1024]; position=inputStream.readLine(buffer, 0, buffer.length); String fileType=""; if(position!=-1){ position = inputStream.readLine(buffer, 0, buffer.length); if(position!=-1){ String upFileName = new String(buffer,0,position); int fileNamePosition = 0; if((fileNamePosition=upFileName.indexOf("."))!=-1){ fileType=upFileName.substring(fileNamePosition).split("\"")[0]; } } } /*判断图片类型 end*/ String fileName = lstr.substring(7)+fileType; if (!direct.exists()) { direct.mkdirs(); } if (!direct.exists()) { direct.mkdirs(); } BufferedImage chooseimage = ImageUtils .getImage(inputStream); FileOutputStream fos = new FileOutputStream(filePath+ "/" + fileName); ImageIO.write(chooseimage, "jpg", fos); fos.close(); chooseimage.flush(); inputStream.close(); return "图片url"; } }
相关文章推荐
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 再次和大家分享我的图片上传插件,基于jquery的上传插件,ajax图片上传。
- 给大家分享一个图片双击放大,双击缩小的第三方库
- 记录一个图片处理类,分享给大家参考
- 带领大家一起做一个ThinkPHP整合jcrop图片上传裁切预览的例子 推荐
- 分享一个图片管理程序,图片批量上传,图片管理(有图片)
- 分享一个图片上传插件(TP5.0)
- 福利:分享给大家一个软件,可以录制gif图片
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 阿庆SQL智能查询分析器,使用delphi开发的一个数据库查询分析管理工具.分享给大家
- php+flash+jQuery多图片上传源码分享
- 一个node.js图片上传显示小应用
- 分享---php 上传图片的代码
- ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例
- 给大家分享一个好的短信接口.
- 和大家分享一个用来做图表的好控件
- 分享一个支持在IE6中PNG图片透明插件
- 分针网——每日分享:ajax +NodeJS 实现图片上传