Java implementation of MP3 merging method _java

Source: Internet
Author: User

This article describes the Java implementation of MP3 merging method. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:

Package test;

Import java.io.*;
Import java.util.*;

public class Test6
{
public static void Main (string[] args) throws Exception
{
String s = "D:/out.mp3"; Output Directory & filename
list<string> list = new arraylist<string> ();
File dir = new file ("D:/aaa"); To traverse the directory, use recursion to get the file, too many files will be finished.
Recursion (Dir.listfiles (), list); Recursive functions
string[] ss = new string[list.size ()];
for (int i = 0; i < ss.length; i++)
{
Ss[i] = List.get (i);
}
System.out.println ();
Combine (s, SS);
}
The. mp3 file of the public static void recursion (file[] FS, list<string> list)//recursively subdirectories.
{
for (File F:fs)
{
if (F.isdirectory ())
{
Recursion (F.listfiles (), list);
}
Else
{
if (F.getname (). EndsWith (". mp3"))
{
List.add (F.getabsolutepath ());
}
}
}
}
Private static Boolean combine (String outfile, string[] infiles) throws Exception
{
File out = new file (outfile);
file[] files = new File[infiles.length];
for (int i = 0; i < files.length; i++)
{
Files[i] = new File (infiles[i]);
}
FileInputStream FIS = null;
FileOutputStream fos = new FileOutputStream (outfile, true); Merging is actually a continuation of the file, written as True
for (int i = 0; i < files.length; i++)
{
FIS = new FileInputStream (files[i]);
int len = 0;
For (byte[] buf = new byte[1024 * 1024]; (len = Fis.read (buf))!=-1;)
{
Fos.write (buf, 0, Len);
}
}
Fis.close ();
Fos.close ();
return true;
}
}

I hope this article will help you with your Java programming.

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.