java - renameTo(File dest) 不可移动文件到dest表示的路径下(环境:mac,linux都不可以)?
PHP中文网
PHP中文网 2017-04-17 15:23:14
0
1
711

写了个简单的测试程序测试是否可以移动一个文件hello.sh到文件夹workshop:

import java.io.*;
import java.util.*;

public class Renamer{
    public static void main(String[] args) {
        File file=new File("/Users/xietiany/Desktop/hello.sh");
        System.out.println("hello.sh exists?"+file.exists());
        File workshop=new File("/Users/xietiany/Desktop/workshop/");
        System.out.println("workshop exists?"+workshop.exists());
        System.out.println(file.renameTo(workshop));
    }
}

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
PHPzhong

The value in

renameTo(File dest) requires the file address, not the folder address. You need to change

/Users/xietiany/Desktop/workshop/

Add a file name after the folder, such as

/Users/xietiany/Desktop/workshop/test.sh

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template