62,621
社区成员
发帖
与我相关
我的任务
分享
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());
}
}
}
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;
}
}