• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Checking the extension of the file

If I have a file which has name  name.zz

I want to check

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

Is there a way to check the extension of the file?
1 Solution
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)
javamate06Author Commented:
Thank you....

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now