Results 1 to 7 of 7
Thread: Directories
- 06-10-2008, 07:58 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Directories
Hi..
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..
- 06-11-2008, 04:05 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You want to read the content of a folder in Java, right?
- 06-11-2008, 04:10 AM #3
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...freedom exists in the world of ideas
- 06-11-2008, 04:47 AM #4
File class
Java io package has a class called File - it behaves remarkably like a file as we know it. One can do:
import java.io.File;
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
See:
java.sun.com/j2se/1.3/docs/api/java/io/File.html
Often, if one knew how to ask the question - you could answer the question.
- 06-11-2008, 10:19 AM #5
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Hi again..
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
- 06-11-2008, 10:20 AM #6
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Yes, that's right..
Just look at my previous post
- 06-11-2008, 04:03 PM #7
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.
Similar Threads
-
JSP – getting list of directories
By Java Tip in forum Java TipReplies: 0Last Post: 01-31-2008, 12:51 PM -
Creating and checking directories with java code
By tim in forum New To JavaReplies: 8Last Post: 01-07-2008, 05:41 AM -
getting paths and directories
By marco in forum Java AppletsReplies: 3Last Post: 11-25-2007, 07:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks