java移动/复制文件 copy/move file
来源:互联网 发布:centos desktop 下载 编辑:程序博客网 时间:2024/04/28 13:41
public class FileAccess
{
public static boolean Move(File srcFile, String destPath)
{
// Destination directory
File dir = new File(destPath);
// Move file to new directory
boolean success = srcFile.renameTo(new File(dir, srcFile.getName()));
return success;
}
public static boolean Move(String srcFile, String destPath)
{
// File (or directory) to be moved
File file = new File(srcFile);
// Destination directory
File dir = new File(destPath);
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
return success;
}
public static void Copy(String oldPath, String newPath)
{
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) {
InputStream inStream = new FileInputStream(oldPath);
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
}
}
catch (Exception e) {
System.out.println( "error ");
e.printStackTrace();
}
}
public static void Copy(File oldfile, String newPath)
{
try {
int bytesum = 0;
int byteread = 0;
//File oldfile = new File(oldPath);
if (oldfile.exists()) {
InputStream inStream = new FileInputStream(oldfile);
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
}
}
catch (Exception e) {
System.out.println( "error ");
e.printStackTrace();
}
}
}
在茫茫网海中收集的两个方法,如果是您的原创,请原谅我的盗用 :(
- java移动/复制文件 copy/move file
- 一天一篇批处理之——Part3:复制/移动文件命令move,copy,xcopy
- Java: File copy in Java – Benchmark(Java文件复制)
- java File(dir, delete, move...) 文件操作
- 4 Ways to Copy File in Java -- Java 复制文件的方法
- C++11类(2)构造,清理,复制,移动 Construction, Cleanup, Copy, and Move
- java中对文件file的操作 新建文件 移动文件 复制文件 删除文件
- 移动文件(夹):move
- wpf copy or move file with dialog
- Android 复制单个文件到指定目录,Android copy file
- java——File复制、移动、删除
- Linux copy文件cp的复制、删除和移动命令
- Unity文件操作 Bug File.Move File.Copy 在不同的系统上获得文件权限不一致
- java 移动文件到其他文件夹(move)
- Java File创建文件复制文件
- 复制文件命令 copy
- 【DOS命令】move 文件移动
- python shutil.move 移动文件
- Google Chrome开发者工具-移动仿真:设备取向和CSS媒体类型
- (顺序容器类)双端队列应用:一个非常长的整数类
- ajax乱码解决总结
- Oracle 过程中执行动态 SQL 或 DDL 语句
- 获取屏幕的分辨率列表,得到屏幕支持的最大分辨率等
- java移动/复制文件 copy/move file
- 编程初学者的救赎 – 献给迷茫的朋友
- 深入浅出MongoDB(二)概述
- Linux 中与 Oracle Database 相关的内核参数详解
- 技术团队新官上任之基层篇
- Android绘图中Path无法序列化的问题解决思路
- Java中Overload和Override的区别
- 技术团队新官上任之中层篇
- Java序列化与反序列化