How to organize, deal with 9CBS technical materials and documents (original, with complete Java source program)
We know that there are many wonderful articles on 9CBS. We can save your article to your local hard drive when you usually browse (or by query). However, when we check out a lot of articles, if each page is opened, then free to the hard disk, it is a waste of time. Some readers use Netant and other tools to download bulk, but after the article is downloaded, we found that the title of the article is not the title I hope. If we use the title of the web page, you can read the article according to the title of the title. I wrote a tool with Java, which will be downloaded from 9cbs, the file name: read_article.aspid = xxx, we are difficult to see its content from the file name. Therefore, it is necessary to change it to the title of the web page. The class name is: SthtmlFileName Usage: Java SethtmlFileName YourDocPath You can use the current path with the path of the document. When processing, a method of directing files directly. So, please do a good job in the original file before the operation. The system I use is: Win2k J2SDK 1.4.0 Time: 2003-10-26 15:31 If you encounter problems, please contact me. Email: Jsczy@eyou.com QQ: 19843788 9CBS Nickname: Hajavaor Program Features: 1, the user provides a directory to automatically change the non-HTM file with a file to the web page. 2. The program only performs the operation of the rename, so the efficiency is high. 3, fully considering the verification of the compliance of the file name 4. There are repetitive files, rename the file, format: Original file name . Copy _X.htm
Advantages:
// Author: hajavaor (9cbs nickname) // name: caozhaoyong, beijing // Date: 2003-10-26 15: 31 // mail: jsczy@eyou.com//qq: 19843788 / / file name: sethtmlfilename.javaImport java.io. *; public class settmlfilename {public static void main (string args []) {string struserpath = system.getProperty ("user.dir"); file dir = null; string strhuangpath = null;
IF (args.length! = 0) {struserpath = args [0] .trim ();
Try {dir = new file (struserpath);} catch (exception ex) {system.err.println ("error:" ex.getMessage ()); system.exit (0);} string strworkingpath = null; if ( Dir.getabsolutefile (). getParent () == null) {strWorkingPath = Dir.getabsolute () "//" Dir.getPath ();} else {strworkingPath = Dir.getPath ();} system .out.println ("Working Directory IS:" StrWorkingPath); System.out.println ("============================ ==== "); if (Dir.IsDirectory () == false) {system.out.println (" Bad Directory. Consult to the usage. "); system.exit (0);
File files [] = null; files = dir.listFiles (); BufferedReader br = null; String strFileContent = null; String strMid = null; String strFileName = null; String strFileFullName = null; int iFileBegin = -1; int iFileEnd = - 1; file newfile = null; int ifileschanged = 0; for (int i = 0; i
"); strfilename = "; strfilecontent =" Br = new bufferedreader (new fileReader (files [i])); strmid = ""; while ((strmid = br.readline ())! = null) {strfilecontent = strmid; if (StrfileContent.indexof (" title > ")! = - 1) {BREAK;} strmid = br.readline ();} br.close (); // read title ifbegin = strfilecontent.indexof (" "); ifileend = strfilecontent.indexof Title> "); if (ifilebegin! = - 1) && (ifilend! = - 1)) {strfilename = StrfileContent.substring (ifilebegin 7, iFilend); strfilename = strfilename.replaceAll (" 9cbs_ document center_","") ;. // replace some un-support chars in the file name strFileName = strFileName.replaceAll ( "<", "" "); strFileName = strFileName.replaceAll ("> "," ""); strFileName = strFileName.replaceAll ( "/" "" "" "); Strfilename = strfilename.replaceAll (": ",": "); strfilename = replaceString (strfilename, '//", "); strfilename = replaceString (strFileName, '/', "/"); strFileName = replaceString (strFileName, '*', "*"); strFileName = replaceString (strFileName,, '?' "?"); strFileName = replaceString (strFileName, ' | ', "|");. // begin to manipulate files strFileFullName = strWorkingPath "//" strFileName; newFile = new File (strFileFullName "htm."); if (newFile.exists ()) {strFileName = ". Replication_-; for (int J = 1 ;; J ) {strfilefullname = strworkingpath "//" StrfileName J; newfile = new file (strfilefullname ". Htm"); if (newfile.exists () == false ) {Strfilename = j; break;}}} system.out.print (strfilename ". Htm--"); if (files [i] .renameto (new file (strfilefullname ". Htm"))))) {system.out .println ("OK.");} else {system.out.println ("failed.");}}}}} catch (exception ex) {system.out.print ("failed. Err:" EX. GetMessage ());}}} System.out.println ("=========================================="); System.out.Println ("Job Finished Files: " ifileschanged);
public static String replaceString (String strSource, char char1, String str) {while (! strSource.indexOf (char1) = - 1) {strSource = strSource.replace (char1, '~'); strSource = strSource.replaceAll ( "~ ", STR);}}} // --- The end of the program.
pre>