URL url = Prop2.class.getResource("/a.properties") //import java.net.URL
System.out.println(url.getPath())
/*** 读取某个文件夹下的所有文件
*/
public static boolean readfile(String filepath) throws FileNotFoundException, IOException {
try {
File file = new File(filepath)
if (!file.isDirectory()) {
System.out.println("文件")
System.out.println("path=" + file.getPath())
System.out.println("absolutepath=" + file.getAbsolutePath())
System.out.println("name=" + file.getName())
} else if (file.isDirectory()) {
System.out.println("文件夹")
String[] filelist = file.list()
for (int i = 0i <filelist.lengthi++) {
File readfile = new File(filepath + "\\" + filelist[i])
if (!readfile.isDirectory()) {
System.out.println("path=" + readfile.getPath())
System.out.println("absolutepath="
+ readfile.getAbsolutePath())
System.out.println("name=" + readfile.getName())
} else if (readfile.isDirectory()) {
readfile(filepath + "\\" + filelist[i])
}
}
}
} catch (FileNotFoundException e) {
System.out.println("readfile() Exception:" + e.getMessage())
}
return true
}
有两种获取链接文件名的方法:
第一种:从连接URL,从描述中获取
第二种:如果第一种获取不到,可以从URL地址中获取
比如这种地址:
http://book.booktxt.com/txtbuk/20130421/xuanhuan/20130421133601180.rar
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)