我想计算没有出现字符串的文件,并且我在目录中有一个文档列表,但它们是多余的。如何从该特定目录中删除重复文件?任何帮助表示赞赏!
public static boolean CompareFiles(File x, File y) throws FileNotFoundException
{ //boolean result=true;
try {
Scanner xs = new Scanner(x);
Scanner ys = new Scanner(y);
boolean result = true;
while (result)
{
if (xs.nextByte() != ys.nextByte()) result = false;
}
return result;
}
catch (FileNotFoundException e)
{
System.out.println(e.getMessage());
return false;
}
}
public static void main(String[] args) throws FileNotFoundException, IOException//
{
File dir = new File("C:/Users/Aravind/Documents/ranked");
File[] fileList = dir.listFiles();
for (int x = 0; x <fileList.length; x++)
{
for (int y = x+1; y < fileList.length; y++)
{
if (CompareFiles(fileList[x],fileList[y]))
{
System.out.println("in calling fn");
fileList[x].delete();
}
//System.out.println(fileList[x]);
}
}