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 复制文件,虽然是复制文件,不过通过本源码你可以学习很多相关的Java基础技巧,比如Java对文件的事件处理、取得目录内容的事件处理、如何弹出文件选择器、如何得到选择文件的绝对路径、如何...
/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/root/.pub': 没有那个文件或目录 (to install the contents of '/root/.pub' anyway, look at the -f option) 解决方法 [root@hadoop1 sbin]# ssh-keygen ...
Java poi复制execl的sheet页,跨文件操作,数据和样式全部复制,工具类
WinMend File Copy【文件复制工具】 V1.3.0绿色汉化免费版WinMend File Copy【文件复制工具】的简介: WinMend File Copy 是一款可以进行文件复制的工具,主要采用的是独特的技术将文件进行复制并有效提高文件的速度...
Java仿Windows 窗口化复制文件功能, class SelectFileListener implements ActionListener { //取得目录内容的事件处理 public void actionPerformed(ActionEvent event) { if (fileChooser....
java执行文件COPY java执行文件COPY java执行文件COPY
Linux文件I/O编程实验代码copy_file,详细步骤看我的博客: http://blog.csdn.net/mybelief321/article/details/8989755
复制文件小助手 Copy Handler
使用java创建文件并复制到另一个文件中
用Java实现的copy命令,类似windows命令行的copy命令,能够给复制任何类型文件
Java IO文件操作类与复制文件实例,有关文本编辑、FileWriter文件写入、FileReade文件读娶DataStream文件数据流、BufferedReader文件暂存器、FileViewer文件浏览器、复制文件Copy等方面的操作要领,仅供学习参考。
public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in);... //复制文件到目标路径 fileUtil.doWriter(data, target_path); }
Windows下复制目录的路径很方便,但是复制文件的全路径比较麻烦。一般的方法是先复制文件所在的目录的路径到记事本中,然后再复制文件名,最后拼接两者。这需要3步才能完成。 CopyPath是资源管理器增加工具,安装后...
使用java 语言实现的文件(夹)复制和粘贴功能
java开源项目团队开发.解压Java File Copy Library.rar即可
java文件夹和文件复制,
* This class is a standalone program to copy a file, and also defines a * static copy() method that other programs can use to copy files. **/ public class FileCopy { /** The main() method of the ...
Type TCxGridPool=class ...//导出文件 StrLooks:TMenuItem;//查找内容[Ctrl+F] AllSelec:TMenuItem;//全选 CxGrid:TCxGrid; DBView:TcxGridTableView; BStyle:Boolean;//是否改变列颜色方案 ...
TeraCopy简体中文版旨在实现以最快的速度在Windows 环境下移动/复制文件,它以智能缓冲技术挖掘在文件传输时的最优速度,同时为了保障文件在移动、复制时的安全性,TeraCopy内置了错误恢复功能,即使在文件传输过程...
文件copy 目录copy