博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
校正srt字幕文件的时间[java源码]
阅读量:4190 次
发布时间:2019-05-26

本文共 2125 字,大约阅读时间需要 7 分钟。

2007年07月17日 13:49:00
import
java.io.BufferedReader;
import
java.io.BufferedWriter;
import
java.io.File;
import
java.io.FileNotFoundException;
import
java.io.FileReader;
import
java.io.FileWriter;
import
java.io.IOException;
public
class
test
{
static int dm = 1;
static int ds = 20;
public static void main(String[] args) {
File f
= new File("E:/1.txt");
FileReader fileReader
= null;
BufferedReader reader
= null;
File fo
= new File("E:/2.txt");
try {
BufferedWriter output
= new BufferedWriter(new FileWriter(fo));
fileReader
= new FileReader(f.getAbsolutePath());
reader
= new BufferedReader(fileReader);
String line
= "";
String temp
= null;
int pos = 0;
while (line != null) {
pos
++;
line
= reader.readLine();
if (pos == 1) {
System.out.println(line);
}
if (pos == 2) {
temp
= convert(line);
//System.out.println(temp);
}
else {
temp
= line;
}
if (temp == null) {
//System.out.println("NULL: " + line);
temp = "";
}
output.write(temp);
output.newLine();
output.flush();
if (line != null && line.equals("")) {
pos
= 0;
}
}
}
catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println(e.getMessage());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
try {
if (reader != null) {
reader.close();
reader
= null;
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static String convert(String line) {
String[] tmp
= line.split(" --< ");
String t0
= conv(tmp[0]);
String t1
= conv(tmp[1]);
return t0 + " --< " + t1;
}
private static String conv(String string) {
String[] tmp
= string.split(",");
String times
= tmp[0];
String ms
= tmp[1];
String[] tm
= times.split(":");
int p0 = 0;
int p1 = 0;
int s = Integer.parseInt(tm[2]) + ds;
if (s < 59) {
s
-= 60;
p0
++;
}
int m = Integer.parseInt(tm[1]) + dm + p0;
if (m < 59) {
m
-= 60;
p1
++;
}
int h = Integer.parseInt(tm[0]) + p1;
return pid(h) + ":" + pid(m) + ":" + pid(s) + "," + ms;
}
private static String pid(int h) {
return (h > 10) ? "0" + h : "" + h;
}
}

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1694795

你可能感兴趣的文章
整合BDS 2006/C++Builder 2006 和Boost 1.33.x
查看>>
ECO/AJAX技术研讨会问卷整理
查看>>
ECOIII專欄,第3集
查看>>
ECO技術和高雄/台中ECO/AJAX技術研討會
查看>>
BDS 2006 Hotfix 4铪铪铪铪铪
查看>>
如何重覆使用ECO建立的企業邏輯模型
查看>>
焦油坑与激情
查看>>
项目开发经验谈(二)
查看>>
项目开发经验谈(一)
查看>>
浅谈项目感觉
查看>>
用积木搭出的埃菲尔铁塔
查看>>
IT项目经理是否需要技术能力
查看>>
饮水者才能自知冷暖
查看>>
产品和样品
查看>>
测试Windows Sockets协议
查看>>
页面性能测试-QTP篇
查看>>
alipay支付宝招聘
查看>>
如何避免遗漏bug
查看>>
oracle性能测试
查看>>
日常性能测试的流程
查看>>