File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Does Java have Wildcards? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does Java have Wildcards?" Watch "Does Java have Wildcards?" New topic
Author

Does Java have Wildcards?

Olivia Terrell
Greenhorn

Joined: Apr 10, 2010
Posts: 2
I am hoping that there is something like the Wildcard in Java...

I want to access a bunch of text files in a folder... The path is /Schedules/Labs/somefilename.txt. There are a BUNCH of text files in the labs folder, and I do not know their complete names. I WANT to say something similar to: String getmyfile[]=loadStrings("/Schedules/Labs/"*".txt") but of course, the '*' operator is not defined that way for Java...

If anyone has any ideas I would be eternally grateful...

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Olivia Terrell wrote:
I want to access a bunch of text files in a folder... The path is /Schedules/Labs/somefilename.txt. There are a BUNCH of text files in the labs folder, and I do not know their complete names. I WANT to say something similar to: String getmyfile[]=loadStrings("/Schedules/Labs/"*".txt") but of course, the '*' operator is not defined that way for Java...


The listFiles() method, used to list all files in a directory, supports a FilenameFilter, which can be used to decide whether a file is allowed or not. You can write a simple filter to only allow txt files.

Or if you must have "wildcards", then you can have the filter use regular expressions, which is almost like file wildcards.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Olivia Terrell
Greenhorn

Joined: Apr 10, 2010
Posts: 2
Thank you Henry!!! That was exactly what I needed to know!
 
jQuery in Action, 2nd edition
 
subject: Does Java have Wildcards?