/**
*
* 解析文件,取出URL地址
*
*/
public static void regexStr(){
String input="飞机但是http://mail.Sohu.com.cn 飞机恺撒";
Pattern p = Pattern.compile("http://[*[a-zA-Z]|w{3}].*[a-zA-Z ]");
Matcher m = p.matcher(input);
m.find();
String str=m.group();
System.out.print(str);
}
/**
* 根据URL,把网页保存到本地
* @param urlStr
* @param filename
* @return
*/
public static boolean getUrlToFileInputStream(String urlStr, String filename){
DataInputStream dataInputStream=null;
try{
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
dataInputStream = new DataInputStream(conn.getInputStream());
}catch(Exception e){
e.getMessage();
}
DataOutputStream dataoutputstream = null;
if(dataInputStream !=null){
try {
dataoutputstream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
byte b[] = new byte[1024*10];
int len = 0;
while ((len = dataInputStream.read(b, 0, 1024)) != -1) {
dataoutputstream.write(b, 0, len);
}
dataoutputstream.flush();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}else{
return false;
}
}