我想用程序从这个 source.txt获取这个 imageurl.txt文件。如果我只尝试使用“p”或“p2”,那么就可以了。但是两种模式都写出来,什么都没有。
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.*;
public class imageurl
{
public static void main(String[] args)
throws IOException
{
for ( int i = 1; i < 5000; i++ )
{
toContent(i);
Pattern p = Pattern.compile("cacheimages/(.*)[\"][ ]*target=");
Pattern p2 = Pattern.compile("</b>[ ]*[(](.*)[)]</div>");
BufferedReader r = new BufferedReader(new FileReader("source\\source"+i+".txt"));
String line;
FileWriter writer = new FileWriter("imageurl\\imageurl"+i+".txt");
while ((line = r.readLine()) != null )
{
Matcher m = p.matcher(line);
Matcher m2 = p2.matcher(line);
while (m.find())
while (m2.find())
{
String c = (m.group(1));
String c2 = (m2.group(1));
System.out.println("<name>"+c2+"</name>_<url>http://www.geocaching.hu/cacheimages/"+c+"</url>"+"\n");
writer.write("<name>"+c2+"</name>_<url>http://www.geocaching.hu/cacheimages/"+c+"</url>"+"\n");
}
}
writer.close();
}
}
private static void toContent(int i)
{
}
}