One of my file and the current path is in
D:\project\major\sample\pp.txt
Let's say I have a file in major
folder say lump.txt
as (D:\project\major\lump.txt)
I don't know the folder name of major but knows the file name (lump.txt
) as it is dynamic which gives the exact folder path of pp.txt alone. I want to move to the previous 1 folder, in this case, the major folder.
So I get the file object by
File file = new File("D:\\project\\major\\sample\\pp.txt")
Now I want to fetch the lump.txt
file which is residing in the previous folder. But all of the below approaches doesn't fetch the file and always returns file doesn't exist
File file = new File(".\\sample\\lump.txt");
if(file.exists()) {
Logger.info("file exist 1");
} else {
Logger.info("file not exist 1");
}
file = new File(".\\.\\sample\\lump.txt");
if(file.exists()) {
Logger.info("file exist 2");
} else {
Logger.info("file not exist 2");
}
file = new File("..\\sample\\lump.txt");
if(file.exists()) {
Logger.info("file exist 3");
} else {
Logger.info("file not exist 3");
}
file = new File("...\\sample\\lump.txt");
if(file.exists()) {
Logger.info("file exist 4");
} else {
Logger.info("file not exist 4");
}
Please advise on how to resolve this problem. How to get the file?
Thanks