?
Solved

Checking the extension of the file

Posted on 2006-07-17
2
Medium Priority
?
174 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 160 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Progress
Starting up a Project
Suggested Courses

777 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