Solved

Checking the extension of the file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 103
wordmultiple challenge 12 121
Non-recursive backtracking, using a stack 1 103
listing all functions in JavaScript 19 179
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now