Recently in a crawler project, the use of a read-write configuration file method, recorded in the future may be used.
Properties Pro =NewProperties ();BooleanIsFirst =true;//Read the file from the class load path, so the file location requires lil bit inputstream in= Propertiesutil.class. getClassLoader (). getResourceAsStream ("Config.properties");p ro.load (in);//Get the Properties property IsFirst= Boolean.parseboolean (String) pro.get ("Isfirststart") ; In.close ();//Gets the path where the properties are located string sourceURL= This. GetClass (). getClassLoader (). GetResource ("Config.properties"). toString ();
Intercept one part of it, (I know it under an experiment) sourceURL= Sourceurl.substring (6, Sourceurl.length ());p Ro.setproperty ("Isfirststart", "false");
FileOutputStream out=NewFileOutputStream (sourceURL);
The modified storage pro.store (out,"Is first start"); Out.close ();
isfirststart=true//config.properties file contents
Read and write Java configuration files