Solved

Checking the extension of the file

Posted on 2006-07-17
2
173 Views
Last Modified: 2012-05-05
If I have a file which has name  name.zz

I want to check

if (name have extension zz)
{
//      Do something
}
else
{
System.out.println(“The file is not a zz file”);
}


Is there a way to check the extension of the file?
0
Comment
Question by:javamate06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
bpmurray earned 40 total points
ID: 17121506
I suppose the easiest way is checking that the ".zz" is at the end of the string , which  means that the last index of that is at the string's length - 3, so you get:

   if (name.lastIndexOf(".zz") == name.length - 3)
0
 

Author Comment

by:javamate06
ID: 17121574
Thank you....

if (name.lastIndexOf(".zz") == name.length() - 3)

0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question