<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 fileSets 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