需求:从一个指定的视频地方读取文件到指定的路径中

package com.wl.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
* @author wanglu
* 需求:从一个指定的视频地方读取文件到指定的路径中
*/
public class IoClassDemo_2 {
public static void main(String[] args) {
MoveVodio mv = new MoveVodio();
try {
mv.getVodio();
System.out.println("读取写入成功");
} catch (IOException e) {
System.out.println("操作失败");
}
}
}

 

/**
* @author wanglu
* 定义一个读取的类
* @serialData 2016-07-18
*/
class MoveVodio{
public void getVodio() throws IOException{
//定义一个指定的路径(源文件)
String fileName = "F:"+File.separator+"1.mp3";
//定义一个输入流(读取文件信息)
FileInputStream in = new FileInputStream(fileName);
//定义一个存储的路径
String otherFileName = "F:"+File.separator+"3.mp4";
//定义一个输出流,(写入到存储路径中)
FileOutputStream os = new FileOutputStream(otherFileName);
//定义一个接收读取的值的变量
int flag = 0;
byte[] bytes = new byte[1024];
//一次读取1024字节,直到读到末尾为止,并把读取的内容写入到存储路径下
while((flag = in.read(bytes))!=-1){
//写入到指定的路径中,一次写入bytes,从0开始,长度为flag
os.write(bytes, 0, flag);
}

//关闭流对象
in.close();
os.close();
}
}

posted @ 2016-07-18 14:20  习惯有迩  阅读(271)  评论(0编辑  收藏  举报