本帖最后由 wangqing 于 2011-11-27 13:34 编辑
/*
将一个指定目录下的java文件的绝对路径,存储到一个文本文件中,建立一个java文件列表清单
*/
package com.day20;
import java.awt.List;
import java.io.*;
import java.util.*;
public class JavaFileList {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File dir=new File("d:\\java");
List<File> list=new ArrayList<File>();
fileToList(dir,list);
File file=new File(dir,"javalist.txt");
writeToFile(list,file.toString());
}
public static void fileToList(File dir,List<File> list)
{
File[] files=dir.listFiles();
for(File file :files)
{
if(file.isDirectory())
fileToList(file,list);
else
{
if(file.getName().endsWith(".java"));
list.add(file);
}
}
}
public static void writeToFile(List<File> list,String javaListFile)
{
BufferedWriter bufw=null;
try {
bufw=new BufferedWriter(new FileWriter(javaListFile));
for(File f :list)
{
String path=f.getAbsolutePath();
bufw.write(path);
bufw.newLine();
bufw.flush();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(bufw!=null)
{
bufw.close();
}
}
}
}
为什么会出现下面的问题:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type List is not generic; it cannot be parameterized with arguments <File>
at com.day20.JavaFileList.main(JavaFileList.java:26)
求高手解决,谢谢! |