Solved

Checking the extension of the file

Posted on 2006-07-17
2
171 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Recommendation vb6 to vb.net or others 14 178
Android development question 2 55
Help Required 2 39
Bot application - advice 3 39
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

830 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