Public static void main (String [] args ){
Try {
String content = "<body> Test6 (url, "d:/a.html", content );
/* System. out. println ("======="
+ Content. subSequence (0, content. length ()-7 ));
System. out. println (content. subSequence (content. length ()-7,
Content. length ()));
Int startIndex = content. lastIndexOf ("</body> ");
System. out
. Println ("======= 2 ===" + content. substring (0, startIndex ));*/
} Catch (Exception e ){
E. printStackTrace ();
}
}
///////////////////////////
Public static void test6 (String path, String path1, String newContent ){
Try {
FileReader fr = new FileReader (path );
BufferedReader br = new BufferedReader (fr );
String node = null;
StringBuffer buffer = new StringBuffer ();
System. out. println ("======================= html content of the original file ================== ");
While (node = br. readLine ())! = Null ){
Buffer. append (node );
}
Int startIndex = buffer. indexOf ("<body> ");
Int endIndex = buffer. lastIndexOf ("</body> ");
If (startIndex! =-1 & endIndex! =-1 ){
StringBuffer str = buffer. replace (startIndex, endIndex,
NewContent );
File file = new File (path1 );
If (file. exists ())
File. delete ();
Else
File. createNewFile ();
FileWriter fileWriter = new FileWriter (path1 );
FileWriter. write (str. toString ());
FileWriter. flush ();
FileWriter. close ();
}
} Catch (FileNotFoundException e ){
E. printStackTrace ();
} Catch (UnsupportedEncodingException e ){
E. printStackTrace ();
} Catch (IOException e ){
E. printStackTrace ();
}
}