Java File.renameTo(File) not working

前端 未结 3 2052
名媛妹妹
名媛妹妹 2021-01-22 09:39

I\'m trying to list a directory\'s contents, and rename certain files.

public void run(String dirName) {
    try {
        File parDir = new File(dirName);
              


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 10:01

    You need to create your new File object with the full pathname of those files. So

    String name = f.getName(); // gets the name without the directory
    

    should likely be:

    String name = f.getAbsolutePath();
    

    (your search/replace may need to change)

提交回复
热议问题