字幕集合list保存为srt文件
新建class,表示单个字幕数据的实体类
public class SrtEntity {
public int number;
public String bg;
public String ed;
public String content;
public int getNumber ( ) {
return number;
}
public void setNumber ( int number) {
this . number = number;
}
public String getBg ( ) {
return bg;
}
public void setBg ( String bg) {
this . bg = bg;
}
public String getEd ( ) {
return ed;
}
public void setEd ( String ed) {
this . ed = ed;
}
public String getContent ( ) {
return content;
}
public void setContent ( String content) {
this . content = content;
}
}
编写保存方法
public void editSrt ( String srtPath, List< SrtEntity> srtList) {
FileOutputStream writeFos = null;
try {
if ( srtList != null && srtList. size ( ) > 0 ) {
writeFos = new FileOutputStream ( srtPath) ;
for ( int i = 0 ; i < srtList. size ( ) ; i ++ ) {
StringBuffer srtBuffer = new StringBuffer ( "" ) ;
srtBuffer. append ( i + 1 )
. append ( "\r\n" )
. append ( srtList. get ( i) . getBg ( ) )
. append ( " --> " )
. append ( srtList. get ( i) . getEd ( ) )
. append ( "\r\n" )
. append ( srtList. get ( i) . getContent ( ) )
. append ( "\r\n" )
. append ( "\r\n" ) ;
writeFos. write ( srtBuffer. toString ( ) . getBytes ( ) ) ;
}
writeFos. close ( ) ;
}
} catch ( FileNotFoundException e) {
e. printStackTrace ( ) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
try {
writeFos. close ( ) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
}