本文介绍了将文本文件从一个目录移动到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过Java程序将文本文件从一个目录移动到另一个目录的问题
程式:
Problem in moving a text file to one directory to another directory through java program
program:
import java.io.File;
// Move File, Directory to another Directory
public class moving {
public static void main(String args[])throws Exception
{
// enter first the names of files as command line argument , first write the oldfile name and then the new directory name e.g.
// java RenameFileDir oldfile.txt newdir
File file = new File(args[0]);
File dir = new File("C:\" "+args[1]);
// destination directory
//The File constructor Creates a new File instance from a parent abstract pathname and a child pathname string.
File f = new File(dir, file.getName());
boolean move= file.renameTo(f);
if (move)
{
System.out.println("File was successfully moved.\n");
}
else
{
System.out.println("File was not successfully moved.\n");
}
}
}
错误:
ERROR:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at moving.main(moving.java:10)
请任何人帮助解决此问题.
Please anybody help to solve this problem.
推荐答案
这篇关于将文本文件从一个目录移动到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!