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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:05:21+00:00 2026-05-25T16:05:21+00:00

I’m working on a program that needs to update a line that depends its

  • 0

I’m working on a program that needs to update a line that depends its value on the result of a line that goes read after. I thought that I could use two BufferedReaders in Java to position the reader on the line to update while the other one goes for the line that fixes the value (it can be an unknown number of lines ahead). The problem here is that I’m using two BufferedReaders on the same file and even if I think I’m doing right with the indexes the result in debug doesn’t seem to be reliable.
Here’s the code:

            String outFinal
            FileName=fileOut;

        File fileDest=new File(outFinalFileName);
        try {
            fout = new BufferedWriter(
                    new OutputStreamWriter(
                            new FileOutputStream(fileDest)));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        FileReader inputFile=null;

        try {
            inputFile = new FileReader(inFileName);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        }
        BufferedReader fin = new BufferedReader(inputFile);

        BufferedReader finChecker = new BufferedReader(inputFile);  //Checks the file and matches record to change
        String line="";
        String lineC="";
        int lineNumber=0;
        String recordType="";
        String statusCode="";
        try {
            while ((lineC = finChecker.readLine()) != null) {
                lineNumber++;
                if (lineNumber==1)
                    line=fin.readLine();
                recordType=lineC.substring(0,3);//Gets current Record Type
                if (recordType.equals("35")){
                    while(!line.equals(lineC)){
                        line=fin.readLine();
                        if (line==null)
                            break;
                        fout.write(line);


                    }
                }else if (recordType.equals("32")){
                    statusCode=lineC.substring(4,7);
                    if(statusCode.equals("XX")){
                        updateRecordLine(line,fout);
                    }
                }


            }
            returnVal=true;

        } catch (IOException e) {
            e.printStackTrace();

        }

Thanks in advance.

  • 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-25T16:05:21+00:00Added an answer on May 25, 2026 at 4:05 pm

    Well, the BufferedReader only reads stuff, it doesn’t have the ability to write data back out. So, what you would need is a BufferedReader to get stuff in, and a BufferedWriter that takes all the input from the BufferedReader, and outputs it to a temp file, with the corrected/appended data.

    Then, when you’re done (i.e. both BufferedReader and BufferedWriter streams are closed), you need to either discard the original file, or rename the temp file to the name of the original file.

    You are basically copying the original file to a temp file, modifying the line in question in the temp file’s output, and then copying/renaming the temp file over the original.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.