Forums Register Login

Does Java have Wildcards?

+Pie Number of slices to send: Send
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...

+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
Thank you Henry!!! That was exactly what I needed to know!
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 727 times.
Similar Threads
how to copy a file from one folder to another folder?
to find the count of text files in a directory..please help..
Search tool to search all class files
Differentiate between file and a folder
connecting midlet to a text file and retrieving data
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:00:44.