Jump to content
  • Advertisement
Sign in to follow this  
3fast3furious

Opening file in java without knowing the name

This topic is 4163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Is there any way to open say an arbitrary log file in java without knowing the whole name? For example, if the file is named log234293847Lbuild.256, I want to open all of the files(perhaps store them in a list) with "build.256" at the end. I don't care about the long number before it. In perl, there is a function called glob that does just that -> @myfiles = glob("*.log"); Is there any way to do this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You can use Jakarta ORO which provides Perl style helper classes. This includes org.apache.oro.io.GlobFilenameFilter; which gives you functionality similar to Perl's glob.

Share this post


Link to post
Share on other sites
I dug out some code I got for such an occasion. Plus, I wanted to see if I could get the code tags to work. It's not fancy and probobly not robust enough, but it should work.


File dir = new File(aDirectoryName);

String[] children = dir.list();
if (children == null)
{
// Either dir does not exist or is not a directory
}
else
{
for (int i = 0; i < children.length; i++)
{
// Get filename of file or directory
String filename = children;

// if ( filename.endswith("build.log") )

aList.add(filename);
}
}


Share this post


Link to post
Share on other sites
Yes I could try getting the directory and doing it that way, however, what I'm attempting to do is read an xml log file on another machine. I'm using CruiseControl for continuous integration of a project and it will write log files every time a build is made. The problem is, for a failed build it will not append a build label to the end of the log file name. And these log files are accessable at a URL to parse like "http://hostaddress:8080/buildresults/project/log23423423423Lbuild.234". But there is no way to get that long number after /log(LongNumber)Lbuild.234. So I need to see if I can parse the file without knowing that number, or simply just open the file without knowing the number, i just know about the build number at the end.

Share this post


Link to post
Share on other sites
Also I'm using the dashboard for Cruise Control which I think runs on the jetty web server, so I don't need to make any socket connections in my own code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!