如何用JAVA读取 mp3文件里包含的 文件名 这类的信息
谢谢~~~~~~~~~~~

解决方案 »

  1.   


    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.text.SimpleDateFormat;
    import java.util.List;public class ParseInput {
    public static void main(String[] args){
    File file = new File("E:/KwDownload/song/张韶涵-隐形的翅膀.mp3");
    System.out.println("文件名:"+file.getName());
    System.out.println("文件大小:"+getFileSize(file));
    System.out.println("文件绝对路径:"+file.getPath());
    System.out.println("是否隐藏:"+file.isHidden());
    System.out.println("最后一次修改时间:"+new SimpleDateFormat("yyyy-MM-dd").format(file.lastModified()));
    } public static String getFileSize(File file) {
    String result = "";
    try {
    Double d = 0d;
    InputStream in = new FileInputStream(file);
    int oneSize = in.available();
    d += oneSize;
    in.close();
    Double dd = Double.parseDouble(d + "") / (1024);
    String size = dd + "";
    String[] str = size.split("\\.");
    // 不到1K
    if (str[0].equals("0")) {
    result = dd + "字节";
    }
    // 1k~1M
    else if (str[0].length() >= 1 && str[0].length() < 4) {
    result = Double.parseDouble(d + "") / (1024) + "00";
    result = result.split("\\.")[0] + "."
    + result.split("\\.")[1].substring(0, 2) + "Kb";
    }
    // 1M~1G
    else if (str[0].length() >= 4 && str[0].length() < 7) {
    result = Double.parseDouble(d + "") / (1024 * 1024) + "00";
    result = result.split("\\.")[0] + "."
    + result.split("\\.")[1].substring(0, 2) + "Mb";
    }
    // 1G以上
    else {
    result = Double.parseDouble(d + "") / (1024 * 1024 * 1024)
    + "00";
    result = result.split("\\.")[0] + "."
    + result.split("\\.")[1].substring(0, 2) + "G";
    }
    // System.out.println("大小为:" + result); } catch (Exception e) {
    e.printStackTrace();
    }
    return result;
    }
    }
      

  2.   

    可以从音乐文件的最后字节中读出!若采用ID3
    ID3标签是MP3音乐档案中的歌曲附加讯息,它能够在MP3中附加曲子的演出者、作者以及其它类别资讯,方便众多乐曲的管理import java.io.*;public class ReadID3 {
        public static void main(String[] arguments) {
            try {
                File song = new File(arguments[0]);
                FileInputStream file = new FileInputStream(song);
                int size = (int)song.length();
                file.skip(size - 128);
                byte[] last128 = new byte[128];
                file.read(last128);
                String id3 = new String(last128);
                String tag = id3.substring(0, 3);
                if (tag.equals("TAG")) {
                    System.out.println("Title: " + id3.substring(3, 32));
                    System.out.println("Artist: " + id3.substring(33, 62));
                    System.out.println("Album: " + id3.substring(63, 91));
                    System.out.println("Year: " + id3.substring(93, 97));
                } else
                    System.out.println(arguments[0] + " does not contain"
                         + " ID3 info.");
                file.close();
            } catch (Exception e) {
                System.out.println("Error -- " + e.toString());
            }
        }
    }因为ID3版本较多,这一个程序对某些歌曲不对!仅供参考吧~~