校正srt字幕文件的时间[java源码]

2024-01-17 10:38

本文主要是介绍校正srt字幕文件的时间[java源码],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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


这篇关于校正srt字幕文件的时间[java源码]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/615746

相关文章

go中的时间处理过程

《go中的时间处理过程》:本文主要介绍go中的时间处理过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1 获取当前时间2 获取当前时间戳3 获取当前时间的字符串格式4 相互转化4.1 时间戳转时间字符串 (int64 > string)4.2 时间字符串转时间

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

Spring WebFlux 与 WebClient 使用指南及最佳实践

《SpringWebFlux与WebClient使用指南及最佳实践》WebClient是SpringWebFlux模块提供的非阻塞、响应式HTTP客户端,基于ProjectReactor实现,... 目录Spring WebFlux 与 WebClient 使用指南1. WebClient 概述2. 核心依

Spring Boot @RestControllerAdvice全局异常处理最佳实践

《SpringBoot@RestControllerAdvice全局异常处理最佳实践》本文详解SpringBoot中通过@RestControllerAdvice实现全局异常处理,强调代码复用、统... 目录前言一、为什么要使用全局异常处理?二、核心注解解析1. @RestControllerAdvice2

Spring IoC 容器的使用详解(最新整理)

《SpringIoC容器的使用详解(最新整理)》文章介绍了Spring框架中的应用分层思想与IoC容器原理,通过分层解耦业务逻辑、数据访问等模块,IoC容器利用@Component注解管理Bean... 目录1. 应用分层2. IoC 的介绍3. IoC 容器的使用3.1. bean 的存储3.2. 方法注

Spring事务传播机制最佳实践

《Spring事务传播机制最佳实践》Spring的事务传播机制为我们提供了优雅的解决方案,本文将带您深入理解这一机制,掌握不同场景下的最佳实践,感兴趣的朋友一起看看吧... 目录1. 什么是事务传播行为2. Spring支持的七种事务传播行为2.1 REQUIRED(默认)2.2 SUPPORTS2

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

Java进程异常故障定位及排查过程

《Java进程异常故障定位及排查过程》:本文主要介绍Java进程异常故障定位及排查过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、故障发现与初步判断1. 监控系统告警2. 日志初步分析二、核心排查工具与步骤1. 进程状态检查2. CPU 飙升问题3. 内存

java中新生代和老生代的关系说明

《java中新生代和老生代的关系说明》:本文主要介绍java中新生代和老生代的关系说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、内存区域划分新生代老年代二、对象生命周期与晋升流程三、新生代与老年代的协作机制1. 跨代引用处理2. 动态年龄判定3. 空间分

Java设计模式---迭代器模式(Iterator)解读

《Java设计模式---迭代器模式(Iterator)解读》:本文主要介绍Java设计模式---迭代器模式(Iterator),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录1、迭代器(Iterator)1.1、结构1.2、常用方法1.3、本质1、解耦集合与遍历逻辑2、统一