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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:59:30+00:00 2026-05-18T23:59:30+00:00

Please I would like your help with the following issue: This is a sample

  • 0

Please I would like your help with the following issue:

This is a sample code customized solely for clarifying my question:

    File accounts_File = new File("Sample_Folder\\example.txt");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    String str_String = ""; //For storing the input from the file.

    fis = new FileInputStream(accounts_File);
    bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);

    while (dis.available() != 0)
    {
        str_String = dis.readLine(); //Reading the line from the file.

        StringTokenizer st = new StringTokenizer(str_String); 

        while (st.hasMoreTokens())
        {
               //I need some help here
        }

    }

    fis.close();
    bis.close();
    dis.close();

The Input File (example.txt) looks as follows: James>Hector>AUS>25

The Objective is simply scanning and replacing “Hector” with “Anderson”. The problem is that the name “Hector” is not known; the only thing known is its location (after the first “>“).

Note: I can change the format of the input file if that makes it easier. As an example I can change the format to something like:

FirstName: James
LastName: Hector
Country: AUS
Age: 25

*Where the program now will scan for the keyword “LastName:” and replace everything following it with “Anderson”.

Thanks in advance for your help!

Any Suggestions are greatly appreciated.

  • 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-18T23:59:31+00:00Added an answer on May 18, 2026 at 11:59 pm

    Keep the format, it looks like a standard csv file (comma separated values, where the “comma” is the “>” char) and csv files are easy to read and write!

    As you can’t replace file content “on the disk”, you’ll have to read the file into memory, rewrite it in memory with the changes needed and rewrite it to the disk.

    A simple model for the file is a two dimensional string array, each line of the file is a row, each value a column, which makes 4 columns. The last name (the string, you want to replace) now is always at matrix[lineNumber][1]. Change the value on the second column for each row and your done.

    For production code, I’d code a class to represent a record. Then, your code could look like this:

    public void replace(File inputFile, String newName) {
      List<Person> persons = new ArrayList<Person>();
    
      // read the file
      List<String> lines = readFile(inputFile);
    
      // create a person instance for each line
      for (String line:lines) {
        String[] values = line.split(">");
        persons.add(new Person(values));
      }
    
      // change the last name
      for (Person person:persons) {
        person.setLastName(newName);
      }
    
      // store all persons to file
      writeFile(inputFile, persons);
    }
    

    Note, that the actual work (file IO, changing names) is done in different methods and classes. This keeps the main algorithm inside the replace method readable.

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

Sidebar

Related Questions

Hi, ive been dealing with this for some time now and need your help.
What would be a clever way to make a 'please wait' control for a
Please read the whole question. I'm not looking for an approach to managing multi-lingual
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please help! I'm really at my wits' end. My program is a little personal
Ok I got a strange issue that I hope someone could help with I
I would like to develop an external website using Facebook Connect instead of an
Edit: I would like to keep the infrastructure as is, so while the framework
So I've been trying to do some research and would like the opinions of
I am new to the world of ASP.NET and SQL server, so please pardon

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.