如何将文件移动到另一个文件夹 [英] how to move file to another folder
本文介绍了如何将文件移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将文件移动到另一个文件夹,但移动的文件显示0kb,我无法打开它。可能是什么错误。
i am able to move files to another folder but the moved file shows 0kb and i'm not able to open it. what could be the mistake.
public static void main(String[] args) throws InterruptedException, IOException
{
File dest = new File("D:/OCR process");
for(int j=0;;j++)
{
File srce=new File("D:/OCR pipe");
File [] files = srce.listFiles();
System.out.println("hai");
if(dest.list().length==0)
{
for (int i = 0; i < 1; i++)
{
//this line weeds out other directories/folders
System.out.println(files[i]);
File sourceFile = new File( "D:\\OCR pipe\\"+files[i].getName());
File destFile = new File("D:\\OCR process\\"+files[i].getName());
sourceFile.delete();
destFile.createNewFile();
System.out.println("This File is error and successfully moved to OCR_ERROR");
}
try
{
Thread.sleep(3000);
}
catch(InterruptedException i)
{
}
}
}
}
推荐答案
你只写了createNewFile
- 为什么?正如Richard MacCutchan试图向您解释的那样,您没有复制任何数据,那么您如何期待比0 kb更好的东西呢? :-)
请使用 https ://docs.oracle.com/javase/tutorial/essential/io/copy.html [ ^ ]。
-SA
You only wrotecreateNewFile
— why? As Richard MacCutchan tried to explain to you, you did not copy any data, so how would you expect anything better than 0 kb? :-)
Please use https://docs.oracle.com/javase/tutorial/essential/io/copy.html[^].
—SA
这篇关于如何将文件移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文