文字列が存在しないファイルを数えたいと思います。ディレクトリ内のドキュメントの一覧がありますが、それらは冗長です。特定のディレクトリから重複ファイルを削除するにはどうすればよいですか? 何か助けに感謝します!特定のディレクトリから重複したファイルを削除する方法
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]);
}
}
1つのディレクトリに冗長ファイルを作成できますか? –
'somedoc.txt'のような'〜somedoc.txt'のようなファイルを意味しますか?もしそうなら、ファイル名が '〜'で始まるかどうかをチェックするだけです。それ以外の場合は、具体的にして、例を挙げてください。 – Thomas
私はインデックス内の単語を検索しており、それに基づいてディレクトリにファイルを作成しているので、冗長ファイルがあります。雅Imeanファイルの内容ではなく、冗長なファイルの内容です。 –