In this list only a typical topic, some of the topics sweep one eye on the idea of not to waste time, want to complete the topic of the comments to stay in the mailbox, see on the hair.
1, batch to the filename of the front plus "igeek_ high-paying employment"
Packagecom.work;ImportJava.io.File; Public classWork0906 { Public Static voidMain (string[] args) {//1, batch to the filename of the front plus "igeek_ high-paying employment"String Path = "D:/wkexp/extjs"; String NewName= "Igeek_ High salary employment"; file[] Files=NewFile (path). Listfiles (); Rename (files,newname); } Public Static voidrename (file[] files,string newName) {if(files==NULL) return; for(inti=0;i<files.length;i++){ //System.out.println ("GetParent" +files[i].getparent ()); //System.out.println ("GetPath" +files[i].getpath ()); //System.out.println ("GetAbsolutePath" +files[i].getabsolutepath ()); //System.out.println ("GetName" +files[i].getname ()); //System.out.println (Files[i].getabsolutepath (). LastIndexOf (File.separator));//File.separator the system-related default name delimiter. //The parent directory is actually redundant .String path = Files[i].getabsolutepath (). substring (0, Files[i].getabsolutepath (). LastIndexOf (File.separator)); //System.out.println ("path" +path); //for the case of a file if(Files[i].isfile () &&files[i].exists ()) { //get file suffix name (non-folder) set starting point is 0 can get the file name (go to the suffix), write it here, actually not used actually is superfluous//String Extension = Files[i].getname (). LastIndexOf (".")! =-1?files[i].getname (). substring (Files[i].getname (). LastIndexOf (".")): ""; //System.out.println (Files[i].getname ()); //Create a new file to replace the original fileFiles[i].renameto (NewFile (path+ "/" +newname+files[i].getname ())); } //the situation of the directory is not considered temporarily, the idea is to copy all the files in the directory, but there should be a more concise approach } }}
Write down unexpectedly also spent half an hour of time, unexpectedly, mainly began to think too much, this would like to be divided into files and folders 2 form, and then split the file name into a prefix and suffix, forget to have renameto this method, but also good for the operation of the file directory is familiar with, the next 2 minutes to fix,
Sure enough, you have to have ideas, you can think of a possible quick package method, the predecessors must have thought of, haha
2. copy files using FileInputStream and FileOutputStream
Public Static voidCopy ()throwsexception{String goalname= "Copy.txt"; FileInputStream FIS=NewFileInputStream (NewFile ("D:/wkexp/extjs/igeek_ High salary employment Igeek_ high salary employment Igeek_ high salary employment CSXY.txt")); FileOutputStream Fos=NewFileOutputStream (NewFile ("D:/wkexp/extjs/copy.txt")); byte[] Buff =New byte[512];//I used the byte array directly, already know 2 performance intLen=0; //FileInputStream Read method reaches end of file return-1 while(len = fis.read (buff))!=-1) {fos.write (buff,0, (int) len); } fos.flush (); Fos.close (); Fis.close (); }
This to the time, 5 minutes just finished, the total can be achieved, so it, by the way, a Glance API documentation, or something will be forgotten, proficiency ah proficiency, sure enough not to write on the forget
2016-9-61, batch to the filename of the front plus "Igeek_ High salary employment" 2, the use of FileInputStream and fileoutputstream copy files