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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:02:26+00:00 2026-05-27T18:02:26+00:00

I am getting data from log file and printing it but it was not

  • 0

I am getting data from log file and printing it but it was not as formated as in log file my code is,

try

    {
    String strpath="/var/new.log";
    FileReader fr = new FileReader(strpath);
    BufferedReader br = new BufferedReader(fr);

    String ch;
    do {
      ch = br.readLine();

      if (ch != null)
        out.println( ch+"\n");
    } while (ch != null);
    fr.close();
    }

        catch(IOException e){

        out.print(e.getMessage());

        }

Data in my file is this format,

[1324649399] Nagios 3.3.1 starting... (PID=3751)
[1324649399] Local time is Fri Dec 23 09:09:59 EST 2011
[1324649399] LOG VERSION: 2.0
[1324649400] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1324649400] ndomod: Could not open data sink!  I'll keep trying, but some output may get lost...
[1324649400] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.

My code is printing it in this Format,

[1324649399] Nagios 3.3.1 starting… (PID=3751) [1324649399] Local
time is Fri Dec 23 09:09:59 EST 2011 [1324649399] LOG VERSION: 2.0
[1324649400] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009
Nagios Core Development Team and Community Contributors [1324649400]
ndomod: Could not open data sink! I’ll keep trying, but some output
may get lost… [1324649400] Event broker module
‘/usr/local/nagios/bin/ndomod.o’ initialized successfully.

How can I get it as it is in the log file?

  • 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-27T18:02:26+00:00Added an answer on May 27, 2026 at 6:02 pm

    If I may suggest, this is a better way for structuring the loop that outputs the log:

    String strpath = "/var/new.log", ch;
    FileReader fr = null;
    try {
        fr = new FileReader(strpath);
        BufferedReader br = new BufferedReader(fr);
        while ((ch = br.readLine()) != null)
            out.println(ch);
    } catch (IOException e) {
        out.print(e.getMessage());
    } finally {
        if (fr != null)
            fr.close();
    }
    

    For solving the formatting problems, do as the other answers suggest, and output the log inside a <pre></pre> tag

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

Sidebar

Related Questions

In the code below, the program is getting string data from the user and
Ive been trying to pull data from an xml file but i keep getting
I am getting raw aac data from web stream and try to put it
I am having URL of PHP file from where i am getting all data
how can i getting data from listbox in second form named listform while i
What are the differences between using SqlDataAdapter vs SqlDataReader for getting data from a
I have the following situation. Im getting data from an external system in the
If I'm getting my data from Mysql like so: $result = $dbConnector->Query(SELECT * FROM
I'm getting some data from the web service and saving it in the core
I am getting some junk data returned from a ToString() call on a DateTime

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.