:lol把自己电脑里的教学视频名称全部汇总了
- /*
- 将文件夹中的文件名称存入txt文件中
- */
- import java.util.*;
- import java.io.*;
- class MovFileTest
- {
- public static void main(String[] args)
- {
- File dir = new File("D:\\Program Files (x86)\\教学视屏");
- List<File> list = new ArrayList<File>();
- toArrayList(dir,list);
- File file = new File(dir,"教学视频汇总.txt");
- toText(list,file);
- }
- public static void toArrayList(File dir,List<File> list)
- {
- File[] file = dir.listFiles();
- for(File f:file)
- {
- if(f.isDirectory())
- toArrayList(f,list);
- else
- {
- String name = f.getName();
- if(name.endsWith(".avi")||name.endsWith(".mp4")||name.endsWith(".rmvb")||name.endsWith(".mkv")||name.endsWith(".flv")||name.endsWith(".wmv"))
- list.add(f);
- }
- }
- }
- public static void toText(List<File> list,File dir)
- {
- BufferedWriter bw =null;
- int count=list.size();
- try
- {
- bw = new BufferedWriter(new FileWriter(dir));
- bw.write("共计"+count+"部影片");
- bw.newLine();
- for(File f :list)
- {
- String path=f.getAbsolutePath();
- //String name=f.getName();
- bw.write(path);
- bw.newLine();
- bw.flush();
- }
-
- }
- catch (IOException io)
- {
- throw new RuntimeException("出错");
- }
- finally
- {
- try
- {
- if(bw!=null)
- bw.close();
- }
- catch (IOException io)
- {
- throw new RuntimeException("关闭资源出错!");
- }
- }
- }
- }
复制代码
|