tag:blogger.com,1999:blog-1848824224762882917.post5500050899026660699..comments2023-07-20T15:18:04.931+05:30Comments on Tech Guru: How to extract a list of filtered files in Java?Vidosh Sahuhttp://www.blogger.com/profile/18017214379597919595noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-1848824224762882917.post-31534432145995683092012-11-01T11:02:27.579+05:302012-11-01T11:02:27.579+05:30Very helpful code for extract a list of filtered f...Very helpful code for extract a list of filtered files in Java.Manoj Singhhttp://www.loadjunction.com/noreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-47797100506636616712012-05-08T16:13:11.370+05:302012-05-08T16:13:11.370+05:30Thank you a lot for giving everyone an extraordina...Thank you a lot for giving everyone an extraordinarily nice opportunity to read from this blog.Bhashkar_Sketchup-Modehttp://www.sketchup4architect.com/noreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-28867536879762827902012-04-27T13:28:57.015+05:302012-04-27T13:28:57.015+05:30it's really outstanding..it's really outstanding..sketchup4architecthttp://www.sketchup4architect.comnoreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-13559210718152634942012-04-25T10:18:28.577+05:302012-04-25T10:18:28.577+05:30Thanks for this great sharing........
import java....Thanks for this great sharing........<br />import java.io.File;<br />import java.io.FileFilter;<br /><br />public class MainClass {<br /><br /> public static void main(String[] args) {<br /><br /> File cwd = new File(System.getProperty("user.dir"));<br /> File[] htmlFiles = cwd.listFiles(new HTMLFileFilter());<br /> for (int i = 0; i < htmlFiles.length; i++) {<br /> System.out.println(htmlFiles[i]);<br /> }<br /> }<br />}<br /><br />class HTMLFileFilter implements FileFilter {<br /><br /> public boolean accept(File pathname) {<br /><br /> if (pathname.getName().endsWith(".html"))<br /> return true;<br /> if (pathname.getName().endsWith(".htm"))<br /> return true;<br /> return false;<br /> }<br />}Bhashkar_Sustainable Designhttp://www.suainlogistics.com/noreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-5929030683641672052012-04-21T16:35:08.921+05:302012-04-21T16:35:08.921+05:30Use a Filter to Retrieve a Specific Subset of File...Use a Filter to Retrieve a Specific Subset of Files in a Directory<br />In Java, File.list() lists all the files in a directory. However, rather than listing all the files and then discarding unnecessary files in your code, this tip will show you how to use a filter to retrieve a specific subset of files.<br />java.io.FilenameFilter is an interface which can be used to get only that set of files that match a specific criteria. Implement this interface to provide your logic of filtering:<br /><br /><br />public class FileExtensionFilter implements FilenameFilter{<br />private String ext="*";<br />public FileExtensionFilter(String ext){<br />this.ext = ext;<br />}<br />public boolean accept(File dir, String name){<br />if (name.endsWith(ext))<br />return true;<br />return false;<br />}<br />}<br />To use this filter in your code:<br /><br />File f = new File("C:\\sample");<br />FileExtensionFilter filter = new FileExtensionFilter(".java");<br />String[] contents = f.list(filter);<br />This example returns only those files with a .java extension.<br /><br /><br />http://www.ecotectanalysis.com/Piyushhttps://www.blogger.com/profile/06749252797129900734noreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-15552536287587315272012-04-16T12:55:07.620+05:302012-04-16T12:55:07.620+05:30Thank you a lot for giving everyone an extraordina...Thank you a lot for giving everyone an extraordinarily nice opportunity to read from this blog.Manoj - outsourcing insurance claims processinghttp://www.dataentryhelp.com/outsourcing-insurance-claims-processing.htmnoreply@blogger.comtag:blogger.com,1999:blog-1848824224762882917.post-83048951531518374342011-12-27T21:20:15.620+05:302011-12-27T21:20:15.620+05:30Nice post you can also check these topics on tech ...Nice post you can also check these topics on <a href="http://www.tech-guruuu.blogspot.com/" rel="nofollow">tech guru</a> and about many products.rajathttps://www.blogger.com/profile/14923769489609597669noreply@blogger.com