code is written when the first test , thanks a directory file named *** are first class, and then use the FIle of renameTo go renamed , but the new name of the neglect of the path , the results directory full empty, go ask those documents , because the return value renameTo have shown true , but I do not know how to find them !
private void reFileName(String directory, File file)
{
// 截字符串subFileString(fileName)
// 新字符串"[ "+subFileString2Num(subFileString(fileName))+" ]"
String fileName = file.getName();
String temp = subFileString(fileName);
String fileNewName = fileName.replaceFirst(beginString + temp + endString, "[" + subFileString2Num(temp) + "]");
file.renameTo(new File(directory + "/" + fileNewName));
}
we do not concern the other code ( nothing more than how they want to sort out a new name ) , so a
file.renameTo (new File (directory + "/" + fileNewName));
with
file.renameTo (new File (fileNewName));
distinction, who said to me , the time with the first two files where they are going to fly ? Seeking to understand
Note:
directory is passed in the directory ,
file is read from the directory the file below
Also a method iterates , this method rule for a file renamed
------ Solution ------------------------ --------------------
java project in the same directory as
------ Solution -------- ------------------------------------
for example, the class path classes / com / a / b / c
then renamed the file should be in the classes under
------ Solution --------------------------- -----------------
System.getProperty ("user.dir")
------ Solution --------- -----------------------------------
see user directory cd ~
------ Solution ------------------------------------------- -
---- - For reference only ---------------------------------------
not find changed files , even before the thought is the project directory.
understand now that want to engage in the Unix root directory which is equivalent to the WINDOWS directory ! Think that perhaps below the root file
because I remember when learning tutorial said JAVA IO operations on files is operating system-independent .
------ For reference only -------------------------------------- -
very difficult to understand , on a trial basis in that computer , no , that is the project directory , right !
System.getProperty ("user.dir") User's current working directory
------ For reference only -------------- -------------------------
very difficult to understand , on a trial basis in that computer , no , that is the project directory , right !
System.getProperty ("user.dir") User's current working directory
is not necessarily a project directory , run in eclipse, when the project's root directory ,
in cmd / shell when running is the directory where you were .
没有评论:
发表评论