You can solve this problem very easily. What you need to do, just create a File object and pass some file name or a directory in it.
We are using a following methods to solve this problem.
isDirectory(): It checks whether the file is a directory or not.
getAbsolutePath(): It returns the absolute path of a file or directory.
Code of the program is given below:
import java.io.*;
|
The output of this example is given below:
| C:\FileOrDirectory>java FileOrDirectory the name you have entered is a file : FileOrDirectory the path is C:\FileOrDirectory\FileOrDirectory |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Determining if a Filename path is a file or a directory View All Comments
Post your Comment