你把代码贴出来一下嘛如果有错误一起也贴出来
不过我觉得可能是你传入的file有问题

解决方案 »

  1.   

    SHFileOperation
    Copies, moves, renames, or deletes a file system object. int SHFileOperation(
        LPSHFILEOPSTRUCT lpFileOp
    );
    Parameters
    lpFileOp 
    [in] Address of an SHFILEOPSTRUCT structure that contains information this function needs to carry out the specified operation. This parameter must contain a valid value that is not NULL. You are responsibile for validating the value. If you do not validate it, you will experience unexpected results. 
    Return Values
    Returns zero if successful, or nonzero otherwise.
      

  2.   

    SHFILEOPSTRUCT
    Contains information that the SHFileOperation function uses to perform file operations. typedef struct _SHFILEOPSTRUCT{ 
        HWND hwnd; 
        UINT wFunc; 
        LPCTSTR pFrom; 
        LPCTSTR pTo; 
        FILEOP_FLAGS fFlags; 
        BOOL fAnyOperationsAborted; 
        LPVOID hNameMappings; 
        LPCTSTR lpszProgressTitle; 
    } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;
     
    Members
    hwnd 
    Window handle to the dialog box to display information about the status of the file operation. 
    wFunc 
    Value that indicates which operation to perform. This member can be one of the following values: 
    FO_COPY 
    Copy the files specified in the pFrom member to the location specified in the pTo member. 
    FO_DELETE 
    Delete the files specified in pFrom. 
    FO_MOVE 
    Move the files specified in pFrom to the location specified in pTo. 
    FO_RENAME 
    Rename the file specified in pFrom. You cannot use this flag to rename multiple files with a single function call. Use FO_MOVE instead. 
    pFrom 
    Address of a buffer to specify one or more source file names. These names must be fully qualified paths. Standard DOS wild cards, such as "*", are permitted in the file-name position. Although this member is declared as a null-terminated string, it is used as a buffer to hold multiple file names. Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom. 
    pTo 
    Address of a buffer to contain the name of the destination file or directory. This parameter must be set to NULL if it is not used. Like pFrom, the pTo member is also a double-NULL terminated string and is handled in much the same way. However, pTo must meet the following specifications: 
    Wildcard characters are not supported. 
    Copy and Move operations can specify destination directories that do not exist and the system will attempt to create them. The system normally displays a dialog box to ask the user if they want to create the new directory. To suppress this dialog box and have the directories created silently, set the FOF_NOCONFIRMMKDIR flag in fFiles. 
    For Copy and Move operations, the buffer can contain multiple destination file names if the fFlags member specifies FOF_MULTIDESTFILES. 
    Pack multiple names into the string in the same way as for pFrom. 
    Use only fully-qualified path names. Using relative path names will have unpredictable results. 
      

  3.   

    这是我之前写的一个移动文件的方法。可供参考:
           /******************************************************
           * 函    数: mvfile
           * 功    能:把指定源文件移动到指定的目的文件,如果出错则重新操作
           * 参数意义:dest_dir_name-目的文件 src_dir_name源文件(需要绝对路径)
           *******************************************************/
          public void mvfile(String dest_dir_name,String src_dir_name)
          {
           String s_destfile=dest_dir_name,s_srcfile=src_dir_name; 
          
           if(s_destfile.equals("")||s_srcfile.equals("")) 
            {
                   System.out.println("源文件或目的文件未指定,请检查参数!");
            }
            else
            {
                try{
           File srcfile=new File(s_srcfile);
           File destfile=new File(s_destfile);
            srcfile.renameTo(destfile);
           }
           catch(Exception e){
           System.out.println("移动文件出错"+e.getMessage());
           }
           }
          }
      

  4.   

    我也需要,刚做的,你参考一下
    import java.io.*;
    public class FileTest 
    {
    public static void main(String[] args) 
    {
    File f=new File("c:\\sun\\text.txt");
    File s=new File("c:\\sun\\sun1.txt");
    if (f.exists())
    {
    f.delete();
    }
    else
    try
    {
    f.createNewFile();
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }

    System.out.println("File name:"+f.getName());
    System.out.println("File path:"+f.getPath());
        f.renameTo(s);
            System.out.println("File name:"+s.getName());
    }
    }
      

  5.   

    import java.io.*;
    public class FileTest 
    {
    public static void main(String[] args) 
    {
    File f=new File("c:\\sun\\text.txt");
    File s=new File("c:\\kg\\sun1.txt");
    System.out.println("File name:"+f.getName());
    System.out.println("File path:"+f.getPath());
    System.out.println("File Size:"+f.length());
        f.renameTo(s);
            System.out.println("File name:"+s.getName());
    System.out.println("File Size:"+s.length());
    }
    }