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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:25:17+00:00 2026-06-03T08:25:17+00:00

I have the following method to read a file and output its lines in

  • 0

I have the following method to read a file and output its lines in reverse order:

public void Reverse(BufferedReader br, PrintWriter pw)
{
  try
  {
    String headLine = br.readLine();

    if (headLine != null)
    {
      Reverse(br, pw);
      pw.println(br.readLine());

    }//if
    pw.println(headLine);      
  }//try
}//Reverse

For some reason, I am not seeing anything in the output file when the code is run It is compiling correctly though. Any ideas?

  • 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-03T08:25:19+00:00Added an answer on June 3, 2026 at 8:25 am

    Firstly, your code won’t even compile – you have a try block with no catch or finally block. When we can’t see your real code, it’s even harder than normal to know for sure what’s going on.

    Secondly, you’re calling readLine() twice for no obvious reason, and then writing out headLine even if it’s null. Shouldn’t your code really be:

    if (headLine != null)
    {
      Reverse(br, pw);
      pw.println(headLine);
    }
    

    without the extra println afterwards?

    My guess is that you’re never flushing or closing the PrintWriter, and you’ve got auto-flush turned off. Don’t do that. Or maybe there’s an exception somewhere, which PrintWriter isn’t going to report because it swallows them. Personally I’d recommend taking just a Writer or BufferedWriter instead of a PrintWriter, and declaring that Reverse can throw IOException. Then make sure that the calling code closes the writer in a finally block.

    I’d also suggest not using recursion for this, unless you’re just using this as a way of investigating recursion. It would be far saner to read the whole file into a list of strings, reverse it, then write it all out.

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

Sidebar

Related Questions

I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
I have a source code file which contains, among others, following lines: public boolean
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method that is replacing a pound sign from the file
i have the following method in a usercontrol protected override void Render(HtmlTextWriter writer) {
I have the following method and interface: public object ProcessRules(List<IRule> rules) { foreach(IRule rule
I have the following method: public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl) The
I have a static utility class, FileUtils which has the following method: public static
We have one text file which has the following text "\u5b89\u5fbd\u5b5f\u5143" When we read
I have to read a file called hello.txt using the following code on java/eclipse/android:

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.