a)文件名不包括域名、路径和URL参数,例如http://www.rs.com/n.op/q/rs?id=1中的文件名是rs。
b)部分URL可能没有文件名,例如http://www.abc.com/,这类统计为“空文件名”。
c)出现在不同URL中的相同文件名视为同一文件名,例如http://www.ceshi.com/hi.php
和ftp://ftp.cdef.com/hi.php为同一文件名
文件内容示例如下:
http://www.test.com/abc/de/fg.php?id=1&url=http://www.test.com/index.html
http://www.ceshi.com/hi.jsp
ftp://ftp.ceshi.com/hi.jsp
http://www.hello.com/cw/hi.jsp?k=8
http://www.hi.com/jk/l.html?id=1&s=a.html
http://www.rs.com/n.op/q/rs?id=1
http://www.abc.com/
package bai;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
public class Test {
public static Set<String> readFile(){
Set<String> set = new HashSet<String>();
String _str;
try {
File f=new File("d:\\test.txt");
BufferedReader reader = new BufferedReader(new FileReader(f));
String line;
while((line=reader.readLine())!=null){
_str = reads(line);
if(!_str.equals("")&&_str!=null){
set.add(_str);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return set;
}
public static String reads(String str){
int _len = str.lastIndexOf("?");
if(_len>0){
str = str.substring(0,_len);
}
return str.substring(str.lastIndexOf("/")+1,str.length()).trim();
}
public static void main(String args[]){
for(String str:Test.readFile()){
System.out.println(str);
}
System.out.println(Test.readFile().size());
}
}
