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

  • Home
  • SEARCH
  • 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 8117205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:05:19+00:00 2026-06-06T04:05:19+00:00

My Question is a design question. Should I use a StringBuilder and read the

  • 0

My Question is a design question. Should I use a StringBuilder and read the file line-by-line, or should I replace?

I’m developing a way to read text from a file. Within the file there can be @@GOTO:"C:\path\to\more.txt"@@. I want to replace everything between the two @@s with the contents of C:\path\to\more.txt. Also, within more.txt there could be another @@GOTO:"C:\path\to\evenmore.txt"@@. So I’m thinking doing this recursively would be the best.

I’m thinking of something like this:

private String replaceGoTo(Pattern pattern, String xmlString) throws IOException {
  Matcher match = pattern.matcher(xmlString);
  while (match.find()) {
    String replacText = IOHelper.fileToString(match.group(2));
    String insert = replaceGoTo(pattern, replacText);
    xmlString = xmlString.replace(match.group(1), insert);
  }
  return xmlString;
}

But I wonder if that’s the most effective way to do it because I’m not using a StringBuilder and I could potentially have a lot of information in those Strings.

Note It’s not broken, I’m just asking about whether there’s a better way to do it. Thanks!

  • 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-06-06T04:05:21+00:00Added an answer on June 6, 2026 at 4:05 am

    Honest answer: Use an existing template library like Freemarker or Velocity.

    Literal answer: Matcher has two methods that come in handy for this kind of situation, appendReplacement() and appendTail(). Both require you to use StringBuffer, which is unfortunate, but it’s the most elegant way to solve such a problem.

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

Sidebar

Related Questions

As I understand from this database design question , you should use nullable fields
I have a question about design winforms. Should I use, or not, group boxes
This should be a very basic design question, but for some reason it doesn't
This is a design question: when do I need to create/use a static method
Basic question: what design principles should one follow when choosing between using a class
Quick design question: Is better to use a separate web app for a REST
Spring 3.1 + Tomcat I have a bit of a design question here: There
I want to design a question structure with some comments. Which relationship should I
I have a software design question on what's the best way to handle a
Another 'design' question. (Technologies in use: PHP , MySQL ) I need to allow

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.