Black Horse programmer--java--file cutting and merging

Source: Internet
Author: User

<p style= "Color:rgb (54, 46, 43); font-family:arial; font-size:14px; line-height:26px; " ><span style= "font-family: Microsoft ya black; line-height:30.796875px; text-indent:28px; " >------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ www.itheima.comtarget= "blank" ></span></p><p style= "Color:rgb (54, 46, 43); font-family:arial; font-size:14px; line-height:26px; " ><span style= "font-family: Microsoft ya black; line-height:30.796875px; text-indent:28px; " >java training </a>, look forward to communicating with you! ---------</span></p>
import java.io.*;import java.util.*;p ublic class Filespiledemos {public static void main (string[] args) throws Exception {//Get files that will need to be cut file = new file ("E:\\myjava\\2015-6-14\\ Phoenix Legend-the most dazzling national wind." Mp36quot;);// Call the custom Cut file feature spilt (file, "E:\\myjava\\2015-6-14\\abc", ". mp3");//Get the directory where files need to be merged file = new file ("e:\\myjava\\ 2015-6-14\\abc ");//Call the custom merge file feature megrefile (Files," Myis "," e:\\myjava\\2015-6-14\\121\\ ",". mp3 ");} 
 set a file merge function//custom merge file function, enter the merged file source directory, merge output file name, merge file output path, and output file format public static void Megrefile (file file,string namess,string paths,string format) throws exception{system.out.println ("merge file function start");// Gets the file in the specified directory and the file in the specified format file[] files = file.listfiles (new merger (format));//Create a container to store these file stream objects Vector<fileinputstream > v = new vector<fileinputstream> (); for (int x=0;x<files.length;x++) {//) to associate the obtained file with the stream and add it to the container v.add (new FileInputStream (Files[x]));} Enumeration<fileinputstream> en =v.elements ();//merge multiple streams sequenceinputstream sis = new Sequenceinputstream (en);// Create output file directory FileOutputStream fos = new FileOutputStream (paths+namess+format); int len = 0;byte[] byt = new Byte[1024];while ((l En=sis.read (byt))!=-1) {fos.write (byt); Fos.flush ();} Sis.close ();} 
Create a filter for a specified format file
Sets a filter for the specified format file for the Transition class merger implements Filenamefilter{private String format; Merger (String format) {This.format=format;} Public Boolean Accept (File dir, String name) {//Return Name.tolowercase (). EndsWith (format);}}

Black Horse programmer--java--file cutting and merging

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.