Merge mp3, vector, Enumeration, SequenceInputStream, FileFilter, anonymous internal class., javafilefilter

Source: Internet
Author: User

Merge mp3, vector, Enumeration, SequenceInputStream, FileFilter, anonymous internal class., javafilefilter

1 package test; 2 3 import java. io. *; 4 import java. util. *; 5 6 public class Test20 7 {8 public static void main (String [] args) throws Exception 9 {10 // search for MP311 File dir = new File ("D:/aaa") from the specified directory "); 12 List <File> list = new ArrayList <File> (); 13 FileFilter filefilter = new FileFilter () 14 {15 public boolean accept (File pathname) 16 {17 if (pathname. getName (). endsWith (". mp3 ") 18 return true; 19 if (path Name. isDirectory () 20 return true; 21 else22 return false; 23} 24}; 25 method (dir. listFiles (filefilter), list, filefilter); // install mp326 doSequence (list) in the list; // merge MP327} 28 private static void doSequence (List <File> list) throws Exception29 {30 Vector <InputStream> vector = new Vector <InputStream> (); 31 for (File f: list) 32 {33 vector. addElement (new FileInputStream (f); 34} 35 Enumeration <InputStream> e = Vector. elements (); 36 SequenceInputStream sis = new SequenceInputStream (e); 37 BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream ("D:/hebingstream"); 38 int len = 0; 39 for (byte [] buf = new byte [1024*1024]; (len = sis. read (buf ))! =-1;) 40 {41 bos. write (buf, 0, len); 42 bos. flush (); 43} 44 sis. close (); // close (); 45 bos. close (); 46} 47 public static void method (File [] files, List <File> list, FileFilter filefilter) 48 {49 for (File f: files) 50 {51 if (f. isDirectory () 52 method (f. listFiles (filefilter), list, filefilter); 53 else54 list. add (f); 55} 56} 57}

 


Find all the files that meet your needs in the specified directory (including subdirectories) (implemented using the FileFilter anonymous internal class), and write

Can I post error exceptions? It should be that an object is a null pointer.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.