我用io将一个64M的视频文件截取成了33份,每份2M,可是第一个视频播放的时候就是完整的视频的播放时间,当播放了不可能就是2M的内容的时候,就开始播放第二个视频了,第二个及其他的视频文件 暴风影音都提示说是无效文件,java代码如下:
package com.gentle.document;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;public class CopyFile {
public static void main(String[]args){
try {
copyFile("d:/flv/yyyyyy.mp4", "d:/flv/copy/");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**以文件流的方式复制文件
* @param src 文件源目录
* @param dest 文件目的目录
* @throws IOException
*/
public static void copyFile(String src,String copyPath) throws IOException{
FileInputStream in=new FileInputStream(src);
File file=new File(src);
String fileName=file.getName().substring(0,file.getName().lastIndexOf("."));
System.out.println(fileName);
int c;
FileOutputStream out=null;
int index=1;
byte buffer[]=new byte[1024];
File newFile=createNewFile(copyPath, fileName, index);
System.out.println(newFile.getAbsolutePath());
out=new FileOutputStream(newFile);
while((c=in.read(buffer))!=-1){
if(newFile.length()==1024*1024*2){
index++;
newFile=createNewFile(copyPath, fileName, index);
out.close();
out=new FileOutputStream(newFile);
}else{
for(int i=0;i<c;i++){
out.write(buffer[i]);
}
}
}
in.close();
}
public static File createNewFile(String copyPath,String fileName,int index){
File file=new File(copyPath+fileName+index+".mp4");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}}请高手解答!谢谢
package com.gentle.document;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;public class CopyFile {
public static void main(String[]args){
try {
copyFile("d:/flv/yyyyyy.mp4", "d:/flv/copy/");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**以文件流的方式复制文件
* @param src 文件源目录
* @param dest 文件目的目录
* @throws IOException
*/
public static void copyFile(String src,String copyPath) throws IOException{
FileInputStream in=new FileInputStream(src);
File file=new File(src);
String fileName=file.getName().substring(0,file.getName().lastIndexOf("."));
System.out.println(fileName);
int c;
FileOutputStream out=null;
int index=1;
byte buffer[]=new byte[1024];
File newFile=createNewFile(copyPath, fileName, index);
System.out.println(newFile.getAbsolutePath());
out=new FileOutputStream(newFile);
while((c=in.read(buffer))!=-1){
if(newFile.length()==1024*1024*2){
index++;
newFile=createNewFile(copyPath, fileName, index);
out.close();
out=new FileOutputStream(newFile);
}else{
for(int i=0;i<c;i++){
out.write(buffer[i]);
}
}
}
in.close();
}
public static File createNewFile(String copyPath,String fileName,int index){
File file=new File(copyPath+fileName+index+".mp4");
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}}请高手解答!谢谢
解决方案 »
- java工程读取mdb数据库,中文乱码无法解决。。。吐血
- java中用线程动态画图的问题
- 请教关于大家是用什么工具开发java桌面程序!
- IllegalMonitorStateException
- 怎么设置JPasswordField的高度?
- 求大神内存分析..
- 各位大哥快帮帮我呀!
- java 如何使用编写好的Oracle pl/sql程序
- 怎么用java做一个功能较全的whiteboard(白板)???哪有源程序??一定给分!!!
- 大家好:org.springframework.beans.factory.NoUniqueBeanDefinitionException
- JFrame里控件不容易显示
- 多线程同步问题 高分
http://www.vckbase.com/document/viewdoc/?id=1464
分割MP3 http://book.51cto.com/art/200912/173835.htm