I need a java method to check text
Asked
Active
Viewed 375 times
0
-
3And what have you tried so far? – NilsH Sep 30 '16 at 12:00
-
There are tools to do this already. Usually using shell scripts but you can call them from Java. – Peter Lawrey Sep 30 '16 at 12:01
2 Answers
0
You can compare size file by file, saving the equal size files into an arraylist and then printing this ArrayList info.
Is a very simple and rude method, maybe if u have a folder with lot of links or things like this will not be working ok.
If u want to investigate more, u can use checksum to check this, but you need knowledge of this aspect.

AFR
- 105
- 4
0
If you want to do this in Java, you can use commons.io Apache library, with the method iterateFiles to get the files inside the directory, and the method contentEquals to check if two files have the same content.
Imports
import org.apache.commons.io.FileUtils;
Code
final String path = "C:/...";
List<File> files = new ArrayList<>();
Iterator iterator = FileUtils.iterateFiles(new File(path), null, false);
while(iterator.hasNext()){
// Compare with the rest of the files in the array
final File file = iterator.next();
for (int i = 0; i < files.size(); i++) {
if (FileUtils.contentEquals(file, files.get(i))) {
// Here you can show the file path name
}
}
// Add the file to the array
files.add(file);
}

Víctor Pariente
- 381
- 2
- 6
- 18
-
Thank you Victor for your nice answer. Could you please write the rest of the code as i am beginner in Java. – Mostafizur Sep 30 '16 at 12:36