I'm really not sure if this topic is advanced or beginner stuff but here goes..
I have a directory on my computer that is in the same directory as the java files that I save to disk..in that directory are all kinds of .htm files..is there any way of "seeing" inside the directory and checking whether a file is of the form that I specify.
Sorry, if this doesn't make sense..
You want to read the content of a folder in Java, right?
I may get all the file names of that directory(Form of array), and check if the extension is an htm file or not....
You may implement a method that receives a file name and returns true if the given filename is a htm file...
If i got what you meant...
Java io package has a class called File - it behaves remarkably like a file as we know it. One can do:
File aFile = new File(".");//
and that will get you the current directory. We then can do
String arrayOfFiles = aFile.list();//
And thus get an array with all the filenames in it just as one would see in windowed gui
Often, if one knew how to ask the question - you could answer the question.
Yeah I used the File class from io but I want to pass a filter to list the files as the type of filter I specified..
i.e. I pass 2 strings; directory name (easy to convert to File) and filter (having trouble converting to FilenameFilter)
I have the filter as "E.*\.htm"..so I want to create an array of all .htm files that have this type of name format..
Thanks in advance.. the File class was really helpul
Yes, that's right..
Just look at my previous post
I had trouble getting filename filter to work, after some reading I decided it was actually and interface. At that time I had just gained the ablility to write an interface, what one does is write a class declaring it implements the interface - then code the methods declared in the interface.
At that point, it is accept(String filename) or some version of that: I would have to look at the docs. In that class, the method would look for htm or html. The String class has a search method, it returns minus one if the string does not contain what you are looking for. There is a way to have it look at the end of the string, but I would have to look it up for you.
It is better if you make several attempts, then ask me when you are stuck. I can now look stuff up efficiently and seem to do well getting people unstuck - sometimes on api's I never heard of.