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 8835447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:15:50+00:00 2026-06-14T09:15:50+00:00

I have content of a file in a StringBuffer. The content of the file

  • 0

I have content of a file in a StringBuffer. The content of the file includes many lines (not on a single line). I want to edit the content of a line from index 4 (just for example) to the end of that line. I use replace() to edit the content of the StringBuffer.

The point is that the replace method has parameters such as starting index and ending index. But I don’t know what is the ending index since each line have different number of characters

I think of using str.indexOf("\n") to find the ending index of the line, but then the file have many lines, so it will return incorrect results.

this is the readFile() if u need to read the code

Thank you

public StringBuffer readFile(){ //read file line by line
    File f = getFilePath(fileName);
    StringBuffer sb = new StringBuffer();
    String textinLine;

    try {
        FileInputStream fs = new FileInputStream(f);
        InputStreamReader in = new InputStreamReader(fs);
        BufferedReader br = new BufferedReader(in);

     while (true){
            textinLine = br.readLine();
            if (textinLine == null) break;
            sb.append(textinLine+ "\n");
        }
        fs.close();
        in.close();
        br.close();
    } ... // just some catch statements heres
}
  • 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-14T09:15:51+00:00Added an answer on June 14, 2026 at 9:15 am

    Use String.indexOf() as you indicated, but pass in the starting position, e.g. indexOf('\n', 4);

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

Sidebar

Related Questions

I have written simple code to get content from xml file to php. $xml
I have script that reads remote file content and writes it to local server.
i have an action that return a file content. i added: Response.AddHeader(Content-Disposition, attactment; filename:\
I am trying to get file content in bytes in Android application. I have
I have a .txt file with content(see first image) I need the content in
I have a long xml file the content of the file are below: <?xml
I have a xml file whose content is <?xml version=1.0 encoding=UTF-8?> <ReturnMessage> <root>ReturnMessage</root> <cancelMessage>Request
I have a description text file with content constructed in such manner: Book title
I'm have a StringBuilder that is writing content to a file. Towards the end
I have a partial called _main_nav.html.erb in views/layout folder, this is content file: <%

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.