Originally Posted by
Juggler
hello friends
Idevelop the project using file concept please any one help me to how to search the file in windows OS
if you search with the name then this code help you fiend the file path..I am not sure it help you or not..
import java.io.*;
public class FileNameReferToSameFile{
public static void main(String args[]){
File file1 = new File("./file.txt");
File file2 = new File("file.txt");
System.out.println("Actual fileName1 = " + file1 + "\n");
System.out.println("Actual fileName2 = " + file2 + "\n");
// It returns false if Filename paths are not equal
boolean b = file1.equals(file2);
System.out.println("It checks whether the file name paths are equal or not" + b);
// Normalize the paths
try {
file1 = file1.getCanonicalFile(); // c:\tapan\filename
file2 = file2.getCanonicalFile(); // c:\tapan\filename
System.out.println("Actual path of filName1 = " + file1 + "\n");
System.out.println("Actual path of fileName2 = " + file2 + "\n");
} catch (IOException e) {
System.out.println("IOException is "+ e);
}
// It returns true if Filename paths are equal
b = file1.equals(file2);
System.out.println("the file name are now equal" + b);
System.out.println("Actual path of fileName1 = " + file1 + "\n");
System.out.println("Actual path of fileName2 = " + file2 + "\n");
}
}