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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:21:15+00:00 2026-05-14T00:21:15+00:00

I need to search a file for a word and return the whole line

  • 0

I need to search a file for a word and return the whole line and the line number with this word, then edit the line and write back to the file. Maybe the line number isn’t necesary to edit a line in a file. I `was reading after seraching with regexp and opening the filechannel of the file, but I can’t get the line number. Maybe there are other better ways to do this. Can you help me how to start this?

  • 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-14T00:21:16+00:00Added an answer on May 14, 2026 at 12:21 am

    First to avoid a potential misconception, you can’t edit a file on the fly by just pointing out the line number and changing the line. You would need to read the whole content and write the whole content back to the same file at any way, even though you only need to edit a single character.

    As to the line numbers, you can just add an incremental counter to the loop wherein you read each line of the file using BufferedReader#readLine(). You can also use the LineNumberReader, but this doesn’t really work as starters would expect. So does for instance setLineNumber() actually not skip the lines to the given line.

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

Sidebar

Related Questions

I have a text file with some content. I need to search this content
I need to search for certain lines in a file that contain numbers, then
I need to search for two particular words in a file line by line
I have a file and searching mutiple value i.e I need to search {Name,Class}
I have a program that I need to be able to search a file
I use file_get_contents(http://www.mydomain.com); to get the content. Then I need to search through it
I need a batch file that will search for the string Gen_1_X. When the
I need to check file extension when search over a directory. if using re
given a large list of alphabetically sorted words in a file,I need to write
I need to add the autocomplete widget to search for a word from the

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.