java - write the value at specific location of property file using servlet -


**************this controller(servlet)****************************

        package com.igate.controller;          import java.io.filenotfoundexception;         import java.io.ioexception;         import java.io.inputstream;         import java.lang.reflect.method;         import java.util.arraylist;         import java.util.properties;         import javax.servlet.requestdispatcher;         import javax.servlet.servletexception;         import javax.servlet.http.httpservlet;         import javax.servlet.http.httpservletrequest;         import javax.servlet.http.httpservletresponse;         import org.apache.commons.configuration.configurationexception;         import org.apache.commons.configuration.propertiesconfiguration;          public class testcontroller extends httpservlet {             private static final long serialversionuid = 1l;             public testcontroller() {                                }                                        protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {                 dopost(request, response);             }                            protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {                   system.out.println("test---------------------------------------------------------------------------");                 response.setcontenttype("text/html");                 string action= request.getparameter("action");                 system.out.println(action);             if(action.equals("proceed"))             {                 string pf =request.getparameter("pf");                               system.out.println(pf);           filereader fr = new filereader("d:/sct_wrk/projectone/src/framework.properties");            bufferedreader br = new bufferedreader(fr);           string line = "";          string newtxt = "";         while ((line = br.readline()) != null){              if ((line.trim()).equals("{platform_end}")){//if line has match need                    line = pf+ "="+ pf; + "\n" + "{platform_end}";//insert new text           }                newtxt += line + "\n";               filewriter fw = new filewriter ("d:/sct_wrk/projectone/src/framework.properties");              bufferedwriter bw = new bufferedwriter(fw);                bw.write(newtxt);       br.close();        bw.close();       fr.close();        fw.close();               }             }             }         --------------------------------------------------------------------------------------------- 

this jsp page ********

        <%@ page language="java" contenttype="text/html; charset=iso-8859-1"             pageencoding="iso-8859-1"%>             <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>          <!doctype html>         <html>         <head>         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">         <title>insert title here</title>         </head>         <body>         <form method="post" action="testcontroller">         <table align="center">         <tr><th>enter platform</th><td> <input type="text" name="pf"></td>     <td><input type="submit" value="proceed" name="action" id ="p"> </td>         </tr>            </table>         </form>         </body>         </html>         ---------------------------------------------------------------------------------------------------        

this property file******

        working_dir = com/test/auto/framework         lib = lib          platform = {windows}         app_type = {web}          platform_start={start}         windows = windows         mac = mac         android = android         ios = ios         platform_end={end}          web = web         native = native         hybrid = hybrid           platform_version = 4.4.2         device = galaxys4         default_url = http://127.0.0.1:4723/wd/hub         grid_url = http://localhost:4444/wd/hub          ie_webdriver_path = {lib}/iedriverserver.exe         chrome_webdriver_path = {lib}/chromedriver.exe         ie_webdriver = iedriverserver.exe         chrome_webdriver = chromedriver.exe          browser_profile_path = {lib}/{browser}/profile          safari_extension = {lib}/{safari}/extension/extension.js         firefox_autoauth_extension = {lib}/{firefox}/extension/autoauth-2.1-fx+fn.xpi          use_firefox_autoauth = false          exec_speed_controller_seconds = 1          log_wait_messages = false      -----------------------------------------------------------------------------    

1). need user enter in platform input text should write in property file exact before " {platform_end}" example.. user enter "linux" should write here- platform_start={start} windows = windows mac = mac android = android ios = ios here-------> linux =linux platform_end={end}

2). want user entered platform should append @ bottom of platform list , before {platform_end} .

how possible.?. if know logic please .. in advance

not sure if apache common config have feature. java io, can read config file line line , rewrite each line addition of new line:

string pf = request.getparameter("pf");     filereader fr = new filereader("d:/sct_wrk/projectone/src/framework.properties");     bufferedreader br = new bufferedreader(fr);     string line = "";     string newtxt = "";     while ((line = br.readline()) != null)     {         if ((line.trim()).contains("platform_end={end}"))         {// if line has match need             line = pf + "=" + pf + "\n" + "platform_end={end}";// insert new                                                             // text         }         newtxt += line + "\n";     }      filewriter fw = new filewriter("d:/sct_wrk/projectone/src/framework.properties");     bufferedwriter bw = new bufferedwriter(fw);      bw.write(newtxt);     br.close();     bw.close();     fr.close();     fw.close(); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -