> Can anyone tell me how to find the exact path of a
> file which is saved in a directory other than the one
> in which the main file is saved?
Use the File class and its getAbsolutePath and getCanonicalPath methods.
> I know there is a
> class called File which has many methods like
> isAbsolutePath() and isPath() but they return the
> path in which the main class is located
Huh? I'm pretty sure that (new File("..")).getCanonicalPath()
does not return the path in which the main class is located, but the parent directory of the directory from which you startet the JVM.
> actually i m trying to write a program which will
> take a name of a file or a directory from the console
> and it should give the entire path of that file or
> directory and this file need not be stored in the
> path of the main class.....It can be stored in any
> drives of my PC....
Ok, then the console input needs to be an absolute path or a path relative to some given directory (usually the one from which the application is started). Java cannot magically guess absolute paths if you just provide a file name. E.g. if I'd use your program and would provide as input "build.xml", how should the program know which file by that name I mean (there are lots of build.xml files in different locations on my machine)?
> ok ...then is there any way to find out what i
> mean?
Recursively traverse you file system looking for the file with the given name. This could take a very long time and may well produce several candidate matches which YOU will have to resolve manually.
> means is thee any code examples that will help
> me for this?
Probably not to do exactly what you want but check out File.listFiles(FileFilter ff) .