I recently asked a much too general and haphazard a question so I'll try and do it the proper way this time.
The task is: write a method returning the extension of the File, i.e. the letters after the last dot(.) in the filename If the filename is hello1.doc, then the method should return doc If there is no dot(.) in the filename, then the method should return “unknown extension”
I'm having trouble with the output of the code not showing anything, let alone the portion of the string that I want it to show
Here is my code:
public Boolean Ftype() {
if
(fileName.indexOf('.') != -1)
{
String x= fileName.toString();
String[] y=x.split(".");
System.out.println("File is of type "+ Arrays.toString(y));
return true;
}
else
{
System.out.println("Unknown File Extension");
return false;
}
}
For f2 = "tests.doc" the output is File is of type [ ]
How can I get the code to output file is of type[doc] or doc?
Thanks in advance for your help,
Dan.
Edit: Apparently Splitting isn't the only way to extract '.doc', apologies if that invalidates my question or makes it too general etc.