Reputation: 212
I'm sure this is simple but I'm usually in PHP and having some difficulty getting used to JSP. I just need the filenames but I get the error listed below
File jsp = new File("/home/www/contents/testing/images/thing");
String f = "";
File[] list = jsp.listFiles();
for(int i=0;i<list.length;i++)
{
f = list[i].split("/");
out.println(f[6]);
}
tomcat error:
The method split(String) is undefined for the type File
Upvotes: 0
Views: 2235
Reputation: 1108722
Look at the javadoc. The File
class does not have the split()
method. This is exactly what the compilation error is trying to tell you. You're liklely confusing it with the String
class which has indeed a split()
method.
If you want to get the file name, just use the getName()
method of the File
class.
f = list[i].getName();
out.println(f);
Note that this problem has nothing to do with JSP. It's all just basic Java. You'd have had exactly the same problem when doing so in a plain Java application with a main()
method instead of a JSP file (which by the way allows for much easier fiddling/unittesting than a JSP file).
Upvotes: 2