| 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
|
|
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!
|
 |
 |
|
|
subject: Does Java have Wildcards?
|
|
|