Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008, 08:58 PM
Member
 
Join Date: Jun 2008
Posts: 4
KevMeistr is on a distinguished road
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..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-11-2008, 05:05 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,561
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You want to read the content of a folder in Java, right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-11-2008, 05:10 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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...
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-11-2008, 05:47 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 578
Nicholas Jordan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-11-2008, 11:19 AM
Member
 
Join Date: Jun 2008
Posts: 4
KevMeistr is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-11-2008, 11:20 AM
Member
 
Join Date: Jun 2008
Posts: 4
KevMeistr is on a distinguished road
Yes, that's right..

Just look at my previous post
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-11-2008, 05:03 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 578
Nicholas Jordan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP – getting list of directories Java Tip Java Tips 0 01-31-2008 01:51 PM
Creating and checking directories with java code tim New To Java 8 01-07-2008 06:41 AM
getting paths and directories marco Java Applets 3 11-25-2007 08:28 AM


All times are GMT +3. The time now is 01:02 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org