在java中,我们对文件的操作,包含了很多方式,下面就是一个移动文件的方法,积累下来,做个记录
1
public
static
boolean
moveFileForBack(String srcFile, String destPath) {
2 try {
3 if ( ! ( new File(destPath).isDirectory())) {
4 new File(destPath).mkdir();
5 // new File("D:/java/newdata/2003-04-14/").mkdir();
6 }
7 } catch (SecurityException e) {
8 System.out.println( " can not make directory " );
9 }
10 File file = new File(srcFile);
11 File dir = new File(destPath);
12 boolean success = file.renameTo( new File(dir, file.getName()));
13 return success;
14 }
还有一个,就是移动的位置,如果没有文件夹,我们就创建一个,是上面代码的深入探究。
2 try {
3 if ( ! ( new File(destPath).isDirectory())) {
4 new File(destPath).mkdir();
5 // new File("D:/java/newdata/2003-04-14/").mkdir();
6 }
7 } catch (SecurityException e) {
8 System.out.println( " can not make directory " );
9 }
10 File file = new File(srcFile);
11 File dir = new File(destPath);
12 boolean success = file.renameTo( new File(dir, file.getName()));
13 return success;
14 }
1
public
static
boolean
moveFileForBack(String srcFile, String destPath) {
2 try {
3 if ( ! ( new File(destPath).isDirectory())) {
4 new File(destPath).mkdir();
5 // new File("D:/java/newdata/2003-04-14/").mkdir();
6 }
7 } catch (SecurityException e) {
8 System.out.println( " can not make directory " );
9 }
10 File file = new File(srcFile);
11 File dir = new File(destPath);
12 boolean success = file.renameTo( new File(dir, file.getName()));
13 return success;
14 }
15
2 try {
3 if ( ! ( new File(destPath).isDirectory())) {
4 new File(destPath).mkdir();
5 // new File("D:/java/newdata/2003-04-14/").mkdir();
6 }
7 } catch (SecurityException e) {
8 System.out.println( " can not make directory " );
9 }
10 File file = new File(srcFile);
11 File dir = new File(destPath);
12 boolean success = file.renameTo( new File(dir, file.getName()));
13 return success;
14 }
15