java移动/复制文件 copy/move file
2008-08-06 11:36
211 查看
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();
}
}
}
在茫茫网海中收集的两个方法,如果是您的原创,请原谅我的盗用 :(
{
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
- 利用spring中的FileCopyUtils.copy()复制文件
- php移动文件的函数 move_uploaded_file()和copy
- 复制文件/文件夹以及子文件夹下的文件; Copy file/folder including subfolder/files
- 利用spring中的FileCopyUtils.copy()复制文件
- php移动文件的函数 move_uploaded_file()和copy
- 文件复制程序 file_copy.c
- java移动/赋值文件 copy/move file
- ubuntu 复制文件到xp (How i can copy file from server(OS:ubuntu 10.04) to my PC
- 以byte[]类型复制文件 Copy a file with read(byte[] data) and write(byte[] data)
- asp.net 文件复制或删除用相对路径,File.Copy中用相对路径,巧用相对路径复制文件
- asp.net 文件复制或删除用相对路径,File.Copy中用相对路径,巧用相对路径复制文件
- IO File.copy 实现文件的复制
- 一天一篇批处理之——Part3:复制/移动文件命令move,copy,xcopy
- 利用FileChannel复制文件 Copy one File to Another【三种方法】
- SharePoint 2013 Rest and SP.js Copyto and Moveto (Rest 和SP.js 基本用法之 复制和移动文件)
- Java基础之访问文件与目录——移动或复制文件和目录(MoveAndCopyFiles)
- PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy
- php移动文件的函数 move_uploaded_file()和copy
- Java: File copy in Java – Benchmark(Java文件复制)