Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Determining if a Filename path is a file or a directory

                         

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.*;

public class FileOrDirectory{
  public static void main(String args[]){
    File directory = new File("Enter any 
                    directory name or file name"
);
    boolean isDirectory = directory.isDirectory();
    if (isDirectory) {
      // It returns true if directory is a directory.
      System.out.println("the name you have entered 
             is a directory  : "  
+    directory);  
      //It returns the absolutepath of a directory.
      System.out.println("the path is "  
                  directory.getAbsolutePath
());
    else {
      // It returns false if directory is a file.
      System.out.println("the name you have
       entered is a file  : " 
+   directory);
      //It returns the absolute path of a file.
      System.out.println("the path is "  +  
                directory.getAbsolutePath
());
    }
  }
}

 

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

Download this example:

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
mouse click count
Combattons la programm
Ñ?о?Ñ?о??Ñ?о??Ñ?о?
tokens
Struts1.1
what is method to find
how to make TATTO
api struts
ASP Ad Management Crea
Servlet Example To Dis
send file
java.sql.SQLException:
Sample program fetch d
convert integer in str
count
date format
<jsp:usebean> tag in j
Photoshop Effects Hole
Photoshop Text Effects
login window
button setName
Inserting data from gu
xml marshling
count sort
edit cell JTable
combo box
Photoshop Drawing Rain
Convert Integer to Flo
J2ME UI components ort
java populate jsf tabl
factory()
generic
Eclipse 3.4 EJB
HTML .htaccess Rewriti
online
ASP Ad Management Rota
msaccess
ado
printwriter
sร?ยà¸?ร???ร?à
selected index
imput
checkLogin
jsf action form
connection class
jar entry
Mouse Event codes
asp.net2.0
JSON AJAX
print values from tabl
html:checkbox is check
d=d^2-4ac
convert java.sql.Time
displaytag
Javascript Menus Image
date to calendar
how to scale image usi
tomcat database conf
analog
TimeTextBox
what is cckies
get array in java usin
exit
java strings
how to access https
ChartDirector Chart an
userid
login jsp
myfaces tomahawk
radio button in html
Flash Dynamic Content
à¹?à¸?à¸?à¹?à¸????à¹?à
how to draw a transpar
NamedQuery
java thread
javascript to display
struts2
Hash Function in Java
java beans
sฦ�ing
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.