遍历读取某个文件夹下所有视频

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012934723/article/details/52458126

/**
* 添加某个文件夹下所有视频步骤一
* @param filepath
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public void p_tianjianpaly() throws Exception{
this.readfile("E:\\学习\\java\\apache-tomcat-7.0.11\\webapps\\Koow\\GOGO");
}
/**
* 添加某个文件夹下所有视频步骤二
* @param filepath
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public boolean readfile(String filepath)
throws FileNotFoundException, IOException {
Timestamp d = new Timestamp(System.currentTimeMillis());
try {

File file = new File(filepath);
if (!file.isDirectory()) {
String sa=file.getName();

System.out.println("文件");
if(sa.indexOf(".jpg")!=-1){
}else if(sa.indexOf(".rar")!=-1){
}else if(sa.indexOf(".zip")!=-1){
}else if(sa.indexOf(".doc")!=-1){
}else if(sa.indexOf(".txt")!=-1){
}else if(sa.indexOf(".png")!=-1){
}else if(sa.indexOf(".txt")!=-1){
}else{
System.out.println("path=" + file.getPath());
System.out.println("absolutepath=" + file.getAbsolutePath());
System.out.println("name=" + file.getName());
try {
Paly paly=new Paly();
paly.setP_time(d);
paly.setP_url(file.getPath().split("Koow")[1]);
paly.setP_uservip(uservipService.finUservips().get(0));
paly.setP_mname(file.getName());
uservipService.add_wy(paly);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (file.isDirectory()) {
System.out.println("--------------------------------------------发现文件夹--------------------------------");
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filepath + "\\" + filelist[i]);
if (!readfile.isDirectory()) {
String sa=readfile.getName();

if(sa.indexOf(".jpg")!=-1){
}else if(sa.indexOf(".rar")!=-1){
}else if(sa.indexOf(".zip")!=-1){
}else if(sa.indexOf(".doc")!=-1){
}else if(sa.indexOf(".txt")!=-1){
}else if(sa.indexOf(".png")!=-1){
}else if(sa.indexOf(".txt")!=-1){
}else{
System.out.println("path=" + readfile.getPath());
System.out.println("absolutepath="
+ readfile.getAbsolutePath());
System.out.println("name=" + readfile.getName());
try {
Paly paly=new Paly();
paly.setP_time(d);
paly.setP_url(readfile.getPath().split("Koow")[1]);
paly.setP_uservip(uservipService.finUservips().get(0));
paly.setP_mname(readfile.getName());
uservipService.add_wy(paly);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

} else if (readfile.isDirectory()) {
readfile(filepath + "\\" + filelist[i]);
}
}

}

} catch (FileNotFoundException e) {
System.out.println("readfile() Exception:" + e.getMessage());
}
return true;
}

展开阅读全文

没有更多推荐了,返回首页