Android中的文件复制--视频和图片复制

来源:互联网 发布:辅助app软件工作室 编辑:程序博客网 时间:2024/06/05 04:34
public class FileOpreateUtils {/** *  * @param fromFile 被复制的文件 * @param toFile 复制的目录文件 * @param rewrite 是否重新创建文件 *  * <p>文件的复制操作方法 */public static void copyfile(File fromFile, File toFile,Boolean rewrite ){if(!fromFile.exists()){return;}if(!fromFile.isFile()){return;}if(!fromFile.canRead()){return;}if(!toFile.getParentFile().exists()){toFile.getParentFile().mkdirs();}if(toFile.exists() && rewrite){toFile.delete();}try {FileInputStream fosfrom = new FileInputStream(fromFile);FileOutputStream fosto = new FileOutputStream(toFile);byte[] bt = new byte[1024];int c;while((c=fosfrom.read(bt)) > 0){fosto.write(bt,0,c);}//关闭输入、输出流fosfrom.close();fosto.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

原创粉丝点击