Is it possible to find and Replace a string inside a textfile using JSP?

Discussion in 'JSP' started by alexantony, Sep 8, 2010.

  1. alexantony

    alexantony New Member

    Joined:
    Sep 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    FileInputStream fs = new FileInputStream("/opt/Abhishek/software/tomcat/webapps/AMS/listpass");
    DataInputStream in1 = new DataInputStream(fs);
    while (in1.available() !=0)
    {
    String str1=in1.readLine();
    StringTokenizer st1 = new StringTokenizer(str1);
    String node=st1.nextToken();
    if (node.equals(sports[i]))
    {
    String pass=st1.nextToken();
    out.println ("<b>"+sports[i]+" <b>");
    out.println("**Your Required Password**");
    out.println(pass);
    out.println("<br></br>");
    
    Hi ,
    I have a text file (named listpass in the above code) inside tomcat-webapps folder containing a node name and its password.You could see the path of the text file at the starting line of the code.The Scene behind the program is once the particular node is clicked the password is retreived for the user against the particular node.What i would need is to change the password in the text file once it is retreived. So i would need to find the password that is retreived recently and change that one with a randomnly generated new password in the text file.

    So can i do this?Is it possible to search for the string in the text file and replace that with a new one using JSP.For your note i am running all my HTML amd JSP inside the same folder where i have the text file in which the string has to be replaced .

    Could anyone give your comments on this please?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice