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

Java Display File-Extension

                         

In this program you will learn how to display the file extension of the file. Here you will be asked to enter the file name and then you will get the extension of the file.

Description of the code:

In the program code given below, you will be asked to enter the file name first as can be observed from the method of java.io.*; package which is BufferedReader();. The compiler will read the file name once you enter it through readLine(); method. Then we have declared the local variables here filename and extension. Now, to find the position of the last dot we have used a method lastIndexOf(); to get the extension. At the last we have applied show(); method to get the extension.

The code of the program is given below:

import java.io.*;
import java.lang.String;

public class FileExtension{
   
  public void show(String extension){
    System.out.println("Extension is" " " + extension);
    }
    public static void main(String args[])throws IOException{
      BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter the file name:");
      String filenameExtension = bf.readLine();
      File filename = new File(filenameExtension);
        if(!filename.exists())
        {
      System.out.println("File does not exist.");
      System.exit(0);
        }
      String extension;
      int dotPos = filenameExtension.lastIndexOf(".");
      extension = filenameExtension.substring(dotPos);
      FileExtension abc = new FileExtension()
      abc.show(extension);
      }

Output of the program:

C:\unique>javac FileExtension.java

C:\unique>java FileExtension
Enter the file name:
test.txt
Extension is .txt

C:\unique>

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:
architecture of a serv
jsf tree node set hr
request.getParameterVa
swing
documentwrite
sending SMS in JAVA
grantchart
Reading File into Byte
click on radio button
jar file
exportdatabasedatainto
Photoshop Wave effect
highlighting and dehig
MurachÐ?????Ð????Ð???Ð
linking codes in java
jsf chat tomcat eclips
Photoshop Effects Hole
shellscriptsusingunixc
passing values from js
Quick Sort
userdefinedexceptionsa
JFileChoosershowOpenDi
network
programinjavatodrawrec
struts pdf file free d
j2me stringItem
Flash Dynamic Content
Combattons
input in java
Agents() in Ms-excel
java bean insert conne
logic iterate
populate drop down fro
Array in Java
InvalidCancelException
int to string
applet viewer browse t
Program to gather Cust
Photoshop Digital Art
strutshibernateexample
upload file using jsp
deploy a JSP and servl
json lib/components/co
json lib/components/co
selectingmultiplefileu
display image
log4j:WARN No appender
sampleprojectsinstruts
Photoshop Text Effects
calling one jsp p
tomcat installation
download package com.s
Java Pass Value
sort a list
retrieve blob field in
displayingimageintojsp
Java Mysql
in photoshop how to ma
ArrayList
writetotextfilereturn
java jtable
date picker
deployapplication
Java I/O
tellmeaboutyourself
how to set text in a t
jar entry
Convert a ASCII into t
servlettovoicespeech
substring search
two integers
one-to-one-Mapping
copy file from client
?¨Ð???¨Ð??¨Ð²â???¨Ð???
difference between arc
asdf
Creating first Struts2
<html:submit
columnwidthPOI
insert data to csv fil
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.