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

时间:2012-06-27 10:33:44

标签: java file-handling servlet-3.0

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();
                }

我发布上面的代码请分享您的观点。这里renameTo()方法无法做到这一点。代码中是否有任何问题?

1 个答案:

答案 0 :(得分:0)

使用FileUtils

FileUtils.moveFile(oldName, newName);