Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does Java have Wildcards?

 
Olivia Terrell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Olivia Terrell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Henry!!! That was exactly what I needed to know!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic