java 获取文本内容信息图片
来源:互联网 发布:linux系统修改ip地址 编辑:程序博客网 时间:2024/06/06 10:54
获取文本内容图片链接地址,并将图片保存到本地
public static String saveContentFile( String contentInfo ) { InputStream fis = null; FileOutputStream fos = null; String oldFileUrl = null;//原文件名称 String newFileUrl = null;//新的文件名称 String filePath = "E:/image/";//将文件保存的系统路径 URL url=null; HttpURLConnection urlconn=null; File file = null; int data=0; int random = 0; try { file = new File( filePath ); if ( !file.exists() )file.mkdirs(); String urlRegex = "http://[^\":<>]*\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga|js|htm)";// 读取图片url的正则表达式 Pattern pattern = Pattern.compile( urlRegex, Pattern.CASE_INSENSITIVE );// 匹配表达式,忽略大小写 Matcher matcher = pattern.matcher( contentInfo ); // 对匹配的集合进行循环处理,将文件保存到本地 while ( matcher.find() ) { oldFileUrl = matcher.group(); // 获取文件信息 url = new URL( oldFileUrl ); urlconn=(HttpURLConnection)url.openConnection(); urlconn.setConnectTimeout( 2000 ); if(urlconn.getResponseCode()!=urlconn.HTTP_OK)continue; fis = urlconn.getInputStream(); // 将文件写入到指定的盘 newFileUrl = filePath + System.currentTimeMillis() + random + oldFileUrl.substring( oldFileUrl.lastIndexOf( "." ) );// 构建新的文件名称 fos = new FileOutputStream( newFileUrl ); data=fis.read(); while(data!=-1){ fos.write( data ); data=fis.read(); } contentInfo = contentInfo.replace( oldFileUrl, newFileUrl );// 将原来的路径替换为现在的新的路径 random++; } } catch ( Exception e ){ e.printStackTrace(); } finally{ try{ if ( null != fis ) fis.close(); if ( null != fos ) fos.close(); } catch ( IOException e ){ e.printStackTrace(); } } return contentInfo; }
- java 获取文本内容信息图片
- Android 获取文本内容及配置信息
- java获取HTML纯文本内容 body
- 获取 GetLastError 文本信息
- HtmlParser 获取文本信息
- java的系统剪切板如何获取一个文本的内容
- 获取内容信息
- java 通过正则表达式 获取纯文本信息
- java过滤html标签获取纯文本信息
- java获取jpg图片信息-有损JPG图片处理
- 获取静态文本的内容
- vc获取剪贴板文本内容
- 获取选择文本内容[转]
- 点击li获取文本内容
- Java 剪切文本内容
- Java读取文本内容
- jquery 获取元素文本信息
- PHP 获取图片信息
- Web开发:我希望得到的编程学习路线图
- Openssl 中DES,AES,BlowFish算法的运算速度比较
- 什么是C/I、SNR、Eb/No和Ec/Io
- STL中map用法详解
- 开发框架
- java 获取文本内容信息图片
- java synchronized详解
- php模拟post和get方法 [discuz的方法]
- 动态创建菜单
- some useful linux commands
- 实验进行中,已经见到曙光
- 传智播客.Net培训基础加强班,推广期优惠已结束 3月31日起恢复原价1980元
- MySQL创建外键关联错误 - errno:150
- eclipse开发spring配置文件xml代码不提示的解决办法