This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Does Java have Wildcards? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 16690
    
  19

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does Java have Wildcards?
 
Similar Threads
Search tool to search all class files
to find the count of text files in a directory..please help..
Differentiate between file and a folder
connecting midlet to a text file and retrieving data
how to copy a file from one folder to another folder?