import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class LrcFilter {
/**
* @param args
*/
String LrcPath = "//home//henyue//lrc.txt";
String[] line;
String[] time;
Map<Double, String> m = new TreeMap<Double, String>();
public static void main(String[] args) {
// TODO Auto-generated method stub
LrcFilter lf = new LrcFilter();
lf.scan();
lf.listAll();
// lf.listTime();
// System.out.println("\n");
// lf.listLrc();
}
// 读入LRC文件,并将时间与歌词分别存入TreeMap的键值对中
public void scan() {
FileInputStream fis;
try {
fis = new FileInputStream(LrcPath);
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(fis));
String data;
while ((data = br.readLine()) != null) {
line = data.substring(1).split("]");
time = line[0].split(":");
double i = 0;
double d = Double.parseDouble(time[0]) * 60
+ Double.parseDouble(time[1]) + i;
// 最后的数字i为校正值
if (line.length > 1) {
m.put(d, line[1]);
} else {
m.put(d, " ");
}
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void listAll(){
Set<Double> mTime = m.keySet();
for (Double dm : mTime) {
System.out.printf("%6.2f - %s\n",dm , m.get(dm));
}
}
public void listTime() {
Set<Double> mTime = m.keySet();
for (Double dm : mTime) {
System.out.print(dm + ", ");
}
}
public void listLrc() {
Collection<String> mLrc = m.values();
for (String sm : mLrc) {
System.out.print("\"" + sm + "\",");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/200815.html原文链接:https://javaforall.cn