Java to implement cool dog music temporary cache file conversion to MP3 file method _java

Source: Internet
Author: User
Tags md5

This article describes the Java implementation of Cool dog music temporary cache file conversion to the MP3 file method. Share to everyone for your reference, specific as follows:

Cool dog Temporary cache file, in fact, is the bar MP3 files are downloaded, but the name seems to be renamed through the MD5 algorithm.

Cool Dog Caches the lyrics while caching the files. This program is based on MD5 management of the corresponding lyrics files and cached files, and then change the cache file to the song name +.mp3 format.

Forgive me for taking so long and not knowing the right class name.

Package com.zhou.run;
Import Java.io.File;
Import Java.util.HashMap;
Import Java.util.Map;
  public class Kugoutempfiletomp3andmodifynametotruename {public static String kgtemp = ". Kgtemp";
  public static String KRC = "KRC";
    public void Change (string TempPath, String krcpath) {File temp = new file (TempPath);
    File KRC = new file (Krcpath);
      if (temp.exists () && temp.getname (). EndsWith (Kgtemp)) {String filename = temp.getname ();
      String filemd5 = filename. substring (0, Filename.lastindexof (kgtemp));
      if (!krc.exists ()) return;
      String krcname = Krc.getname ();
      String krcmd5 = krcname.substring (Krcname.lastindexof ("-") + 1, krcname.lastindexof (KRC)-1);
      String mp3name = krcname.substring (0, Krcname.lastindexof ("-")); if (Krcmd5.equals (FILEMD5)) {String path = Temp.getpath (). substring (0, Temp.getpath (). LastIndexOf ("\
        ")); File Mp3file = new file (path + "\" + Mp3name +). mp3 ");
      Temp.renameto (Mp3file);
      SYSTEM.OUT.PRINTLN (filename + "" + filemd5);
    System.out.println (Krcname + "" + Mp3name + "" + krcmd5);
    } public void Changebydir (String temppath,string krcpath) {map<string,file> temps = Filemd5map (TempPath);
    map<string,string> mp3names = Krcnamemd5map (Krcpath);
      For (String Key:temps.keySet ()) {File F = temps.get (key);
        if (f.exists ()) {String path = F.getpath (). substring (0, F.getpath (). LastIndexOf ("\"));
        String mp3name = Mp3names.get (key);
        File Mp3file = new file (path + "\" + Mp3name + ". mp3");
          if (F.renameto (Mp3file)) {System.out.println (F.getname () + "to" +mp3file.getname ());
        System.err.print ("SUCCESS");
    File> filemd5map (String path) {File Dirfile = new File (path) map<string}}}
    map<string, file> map = null; if (Dirfile.isdirectory ()) {map = new HAshmap<string, file> ();
          For (File f:dirfile.listfiles ()) {if (F.exists () &&f.isfile () && f.getname (). EndsWith (kgtemp)) {
          String filename = F.getname ();
          String filemd5 = filename.substring (0, Filename.lastindexof (kgtemp));
        Map.put (FILEMD5, F);
  }} return map;
    Public map<string,string> Krcnamemd5map (String path) {File Dirfile = new File (path);
    map<string, string> map = null;
      if (Dirfile.isdirectory ()) {map = new hashmap<string, string> ();
          For (File f:dirfile.listfiles ()) {if (F.exists () &&f.isfile () && f.getname (). EndsWith (KRC)) {
          String krcname = F.getname ();
          if (!krcname.contains ("-")) continue;
          String krcmd5 = krcname.substring (Krcname.lastindexof ("-") + 1, krcname.lastindexof (KRC)-1);
      String mp3name = krcname.substring (0, Krcname.lastindexof ("-"));    Map.put (KRCMD5, mp3name);
  }} return map; } public static void Main (string[] args) {kugoutempfiletomp3andmodifynametotruename KTF = new Kugoutempfiletomp3and
    Modifynametotruename ();
    /*string TempPath = "D:/kugou/mp3/2fad259e357078e89404be12e1fd7ae3.kgtemp";
    String Krcpath = "d:/kugou/lyric/Jay Chou, Lin-how -2FAD259E357078E89404BE12E1FD7AE3.KRC"; Ktf.
    Change (Temppath,krcpath); */String TempDir = "D:/kugou/mp3";
    String krcdir= "D:/kugou/lyric"; Ktf.
Changebydir (TempDir, Krcdir);

 }

The change (string,string) method is used only for testing purposes. Tune a string or something.

The main use of the Changebydir method, the parameters are temporary files folder and Lyrics Files folder

More about Java algorithms Interested readers can view the site topics: "Java data structure and algorithms tutorial", "Java Operation DOM node skills summary", "Java file and directory operation tips Summary" and "Java Cache operation Tips"

I hope this article will help you with 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.