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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:41:57+00:00 2026-05-13T16:41:57+00:00

Concerning my previous question , I found out that maven can’t really output jboss

  • 0

Concerning my previous question , I found out that maven can’t really output jboss console. So I thought I’d like to make workaround it. Here is the deal:

While jboss is running, it writes console logs into server.log file, so I’m trying to retrieve the data as it comes in, because every few seconds the file is changes/updated by jboss I’ve encountered some difficulties so I need help.

What I actually need is:

  1. read file server.log
  2. when server.log is changed with adding few more lines output the change

Here is the code so far I got, there is a problem with it, it runs indefinitely and it starts every time from the beginning of the file, I’d like it to continue printing just the new lines from server.log. Hope it makes some sense here is the code:

import java.io.*;


class FileRead 
{
   public static void main(String args[])
  {
      try{
   for(;;){ //run indefinitely
    // Open the file 
    FileInputStream fstream = new FileInputStream("C:\\jboss-5.1.0.GA\\server\\default\\log\\server.log");
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    }
  }
      catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}

According to the Montecristo suggestion I did this :

import java.io.*;

class FileRead {
    public static void main(String args[]) {
        try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream(
                    "C:\\jboss-5.1.0.GA\\server\\default\\log\\server.log");
            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String line;
            // Read File Line By Line
            while ((line = br.readLine()) != null) {
                // Print the content on the console
                line = br.readLine();
                if (line == null) {
                    Thread.sleep(1000);
                } else {
                    System.out.println(line);
                }

            }
            // Close the input stream
            in.close();

        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
}

And it still not working, it just printed the original file.. although the file changes constantly nothing happens.. nothing gets printed out except the original log file.

HERE IS THE SOLUTION: tnx Montecristo

import java.io.*;

class FileRead {
    public static void main(String args[]) {
        try {

            FileInputStream fstream = new FileInputStream(
                    "C:\\jboss-5.1.0.GA\\server\\default\\log\\server.log");

            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String line;

            while (true) {

                line = br.readLine();
                if (line == null) {
                    Thread.sleep(500);
                } else {
                    System.out.println(line);
                }

            }

        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}

Also see :

http://vanillajava.blogspot.co.uk/2012/08/java-memes-which-refuse-to-die.html

  • 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-13T16:41:57+00:00Added an answer on May 13, 2026 at 4:41 pm

    I don’t know if you’re going in the right direction but if I’ve understood correctly you’ll find this useful: java-io-implementation-of-unix-linux-tail-f

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

Sidebar

Related Questions

Okay the previous question was answered clearly, but i found out another problem. What
I have question concerning a function I created. I would like to show the
Following up on my previous question concerning the Windows 7 taskbar , I would
This question is a followup to a previous question , that was resolved thanks
The problem below is ralated to my previous question Converting static link library to
I have a question concerning this code which I want to run on QNX:
I have a question concerning subtypes of built-in types and their constructors. I want
My question is concerning SQL connection status, load, etc. based on the following code:
Very similar to this question , I am trying to convert a project that
This question is a dual of Constructor with by-value parameter & noexcept . That

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.