ho risolto con l'exist() il problema ke con questo pezzo di codice mi fa ciò ke deve fare solo ke se inserisco un altro elemento anzikè sostituirmi un pezzo di codice con un altro nella pagina web mi cancella tutto
cosa ho sbagliato?
vorrei cercare di prendere una sottostringa e di sostituirla con un'altra e di continuare a scrivere nello stesso file .htm
codice:
//creamo un oggetto FileWriter per poter creare una pagina web inserendo in un combobox
			//gli id degli item aggiunti	
			try {
				//creamo un oggetto File per creare un file .htm sul disco
				String webPath = new String ("C:/Programmi/Apache Software Foundation/Tomcat 6.0/webapps/ITemRecommender/ChooseItem.htm");
				File TempWebPage = new File (webPath);
				//verifica se il file esiste o meno
				if (!TempWebPage.exists()){
					//se il file non esiste lo crea
					TempWebPage.createNewFile();
					//se il file non esiste provvede a inserirvi gli elementi
					BufferedWriter webPage = new BufferedWriter( new FileWriter("C:/Programmi/Apache Software Foundation/Tomcat 6.0/webapps/ITemRecommender/ChooseItem.htm"));
					String text1 = "<html><head><title>Choose Item</title></head><body><h2>Choose An Item</h2><FORM id=\"form_item_chose\" METHOD=\"post\" ACTION=\"ChooseItem\"><b ID=\"ItemChose\">Choose an item to rate to a customer.[/b]
Choose one of these
<SELECT NAME=\"chose\"><OPTION>";
					String text2 = "</OPTION></SELECT></p>


<INPUT id = \"send\" TYPE=\"submit\" VALUE=\"Send\" /></p>
</FORM></body></html>";
					webPage.write(text1 + id + text2);
					webPage.close();
				}
				else{
					//se il file esiste provvede ad aggiungere altri elementi
					BufferedReader readWebPage = new BufferedReader( new FileReader("C:/Programmi/Apache Software Foundation/Tomcat 6.0/webapps/ITemRecommender/ChooseItem.htm"));
					String line;
					while ((line = readWebPage.readLine()) != null){
						if (line.endsWith("</SELECT></p>


<INPUT id = \"send\" TYPE=\"submit\" VALUE=\"Send\" /></p>
</FORM></body></html>"));
						BufferedWriter webPage = new BufferedWriter( new FileWriter("C:/Programmi/Apache Software Foundation/Tomcat 6.0/webapps/ITemRecommender/ChooseItem.htm"));
						String text3 = "";
						webPage.write(line.replaceAll("</SELECT></p>


<INPUT id = \"send\" TYPE=\"submit\" VALUE=\"Send\" /></p>
</FORM></body></html>", "<OPTION>" + id + "</OPTION></SELECT></p>


<INPUT id = \"send\" TYPE=\"submit\" VALUE=\"Send\" /></p>
</FORM></body></html>"));
						webPage.close();
					}
					readWebPage.close();
				}
			}
			catch (IOException ex) {
				System.err.println(ex);
			}
/*			catch (FileNotFoundException ex) {
				System.err.println(ex);
			}*/
la parte else dell'if di exists non va come dovrebbe andare.. cosa ho sbagliato?