如何在java中使用新名称重命名简历(.doc)

如何在java中使用新名称重命名简历(.doc),java,file-handling,servlet-3.0,Java,File Handling,Servlet 3.0,我在上面发布了我的代码,请分享你的观点。这里renameTo方法无法做到这一点。代码中有任何问题吗 使用: FileUtils.moveFileoldName,newName; 你能说出你遇到的错误吗,因为它对我来说很好。当我在控制台上打印rename时,它返回false,如果rename=false,它将不会进入if block,因此我无法在新文件中写入内容。也许你的旧.doc仍被其他程序打开?@Liu-Yan,是的,您是对的,因为当我手动更改名称时,它会显示以下消息:操作无法完成,因为文件是

我在上面发布了我的代码,请分享你的观点。这里renameTo方法无法做到这一点。代码中有任何问题吗

使用:

FileUtils.moveFileoldName,newName;
你能说出你遇到的错误吗,因为它对我来说很好。当我在控制台上打印rename时,它返回false,如果rename=false,它将不会进入if block,因此我无法在新文件中写入内容。也许你的旧.doc仍被其他程序打开?@Liu-Yan,是的,您是对的,因为当我手动更改名称时,它会显示以下消息:操作无法完成,因为文件是在JAVATM Platform SE二进制文件中打开的。但我无法理解它在我的程序中打开的位置。然后@jitendra尝试关闭打开文件的程序,然后重试..:
String oldName = D:\careers.bstalents.com\build\web\uploads\Resume\old.doc;
String newName = D:\careers.bstalents.com\build\web\uploads\Resume\new.doc;

           File newFile = new File(newName);
           File oldFile = new File(oldName);
           boolean rename = oldFile.renameTo(newFile);
           if (rename) {

                    outs.write(formFile.getFileData());
                    outs.close();*/
                    FileOutputStream fileOutStream = new FileOutputStream(newFile);
                    fileOutStream.write(resume.getFileData());
                    fileOutStream.flush();
                    fileOutStream.close();
                }