2

Greeting ,Currently I am using the OReilly MultipartRequest class and i want to rename the complete file name before upload.

MultipartRequest m = new MultipartRequest(request, Path,5024 * 1024, new FileRenamePolicy() {
                    @Override
                    public File rename(File arg0) {
                        boolean result = arg0.renameTo(new File(arg0
                                .getParentFile() + "title"));
                        if (result) {
                            System.out.println("Renamed");
                        }
                        return arg0;
                    }
                });

But every time result is false.Please guide me where am wrong.I am new to java Technology

4

3 回答 3

0

尝试这个...

boolean result = arg0.renameTo(new File(arg0.getParentFile(), "title"));

或者这个...(注意文件分隔符)

boolean result = arg0.renameTo(new File(arg0
        .getParentFile().getAbsolutePath() + File.separator + "title"));

如果它已经存在,您可能必须在尝试重命名之前立即将其删除...

File newFile = new File(arg0.getParentFile(), "title");
if (newFile.exists()) newFile.delete();
于 2013-04-16T10:45:37.130 回答
0

查看

  1. 用于 JVM 的写访问
  2. 对于只读文件系统
  3. 目标文件不存在
  4. 目标文件名没问题
  5. 源文件存在
  6. 源文件未写锁定
  7. 源文件未在其他编辑器中打开
  8. 可以删除源文件...等等等等

这有帮助吗?

于 2013-04-16T10:23:43.023 回答
0

查看文档 Returns a File object holding a new name for the specified file.试试这个:

public File rename(File arg0) {
    return new File(arg0.getParentFile() + "title"));
}
于 2013-04-16T10:47:37.573 回答