Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6979103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:50:35+00:00 2026-05-27T17:50:35+00:00

I have to delete and rename the files in doPost.but while executing some of

  • 0

I have to delete and rename the files in doPost.but while executing some of the files are deleting some othes are not. When the same code i run in java the operation is succesfully carried out.here is the code i used for deleating files inside a directory.The same below code is i used in servlet.

public static void updateRootFile(String directorypath, String appID, String[] appName) throws IOException {
    try {

        FileInputStream fin = null;
        File[] listOfFiles=fileLists(directorypath);
        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                rootFiles = listOfFiles[i].getName();
                if (rootFiles.endsWith(".properties") || rootFiles.endsWith(".PROPERTIES")) {
                    fin = new FileInputStream(directorypath + rootFiles);
                    properties.load(new InputStreamReader(fin, Charset.forName("UTF-8")));
                    String getAppName = properties.getProperty("root.label." + appID);
                    String propertyStr = "root.label." + appID;
                    saveFile(fin, getAppName, directorypath + rootFiles, propertyStr, appName[i]);
                }
            }

        }

    } catch (Exception e) {
        System.out.println("expn-" + e);

    }

}

public static void saveFile(FileInputStream fins, String oldAppName, String filePath, String propertyStr, String appName)
        throws IOException {
    String oldChar = propertyStr + "=" + oldAppName;
    String newChar = propertyStr + "=" + appName;
    String strLine;
    File f1 = new File(filePath);
    File f2 = new File("C:\\Equinox\\RootSipResource\\root\\root_created.properties");      
    BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(f1), "UTF-8"));
    OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f2), "UTF-8");
    while ((strLine = br.readLine()) != null) {
        strLine = strLine.replace(oldChar, newChar);
        out.write(strLine);
        out.write("\r\n");
    }
    out.flush();
    out.close();
    br.close();
    fins.close();
}

Servlet code:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import root.sip.RootSipResourceApp;

public class SendRedirect extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html; charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
        String strDirectorypath = (String) request.getParameter("txtfileBrowse");
        request.setAttribute("directorypath", strDirectorypath);
        String strappID = request.getParameter("txtAppID");
        String[] appNames = {strEn, strAr, strBg, strCs, strDa, strDe, strEl, strEs, strFi, strFr, strHe, strHr, strHu, strIt,strLw, strJa, strKo, strNl, strNo, strPl, strPt, strRo, strRu, strSk, strSl, strSv, strTr, strZh, strZh_TW };

        RootSipResourceApp.updateRootFile(strDirectorypath, strappID, appNames);
        System.out.println("after................");
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
        dispatcher.forward(request, response);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:50:36+00:00Added an answer on May 27, 2026 at 5:50 pm

    It could be that your static methods are being accessed by multiple Servlet Threads at once.

    You can make the saveFile() and updateRootFile() synchronized to prevent being accesed by multiple threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to delete some elements of my array, but without rearrange array. If
I have a delete issue at the moment. We do not have permission to
I want to have a delete user link in a normal Activerecord table, but
Okay, so my issue is that I have to catch delete and rename events
I have some code that watches the file system for changes and updates a
I have a delete button on a table and a jquery on click eventlistener
I have a delete form wherein the user will enter the pnum to be
I have to delete all rows of a model with condition fkey_id = 1
I have a delete button on my web site which I want to add
I have a delete button and on clicking cancel on the confirm box, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.