This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Randomaccessfile read line from given start and end location

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I have a log file of huge size. I have to view the log files from the reverse (most recent logs).
Total file length (no of lines): 10000
startPosition: 0 (from end of file)
toPosition: 100 (from end of file to 100 lines in reverse)

so i just need to print last 100 lines, but if i change the startPosition and toPosition to (100 - 200) it should read the next 100 lines in reverse skipping the last 100 lines.

Please do the needful. Below code displays the last n number of lines based on the input we provide. but i need to tweek this based on the start and end position.

 
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow...

Is this for work or for a school assignment? If it's for work, why don't you just install Cygwin and use the tail utility? You even have TailForWin32 if you don't want to use Cygwin. (I'm assuming you're on Windows because of your hard-coded filename)
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just a utility jsp to view the logs instead of logging into the DEV server. Please share your thoughts on the same
 
Junilu Lacar
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, so you're going to put all this Java code into a JSP? Like, as a scriptlet?
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu,

Yes, this piece of code will be placed as scriplet within jsp. Let me know if there is any other right way of doing this with simple java API, but im using java 1.4 version.
Thanks for your early reply.
 
Junilu Lacar
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may see the shadow of a Bear soon... (if you don't get it, Author and ninkuma Marshal Bear Bibeault roams these parts, looking for people who still, in this day and age, use JSP scriplets. He usually gives them a piece of his mind and lets off with a warning)

I will move this to the JSP forum where they can give you some sound advice.
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Junilu

I just need to understand the logic behind. By using randomaccessfile i just need to print the portion of log file. How do we achieve in JAVA? now i am able to print the log file in reverse based on the no. of lines to be displayed and it is printing me the exact line nos. but i need to print the next nth lines. Pleaes do the needful.
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

prabhu pandurangan wrote:Hi Team,

I have a log file of huge size. I have to view the log files from the reverse (most recent logs).
Total file length (no of lines): 10000
startPosition: 0 (from end of file)
toPosition: 100 (from end of file to 100 lines in reverse)

so i just need to print last 100 lines, but if i change the startPosition and toPosition to (100 - 200) it should read the next 100 lines in reverse skipping the last 100 lines.

Please do the needful. Below code displays the last n number of lines based on the input we provide. but i need to tweek this based on the start and end position.

 
Junilu Lacar
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

prabhu pandurangan wrote:but i need to print the next nth lines. Pleaes do the needful.


I sorry, but nobody around here really needs to do anything. I know "Please do the needful" is probably some kind of regional linguistic quirk and we're very aware of non-native English speakers and language differences around here. However, if I may offer some advice on this, "Please do the needful" does not come across very well. I suggest you use alternatives like these instead:

"Any ideas on what I should do?"

"I've searched using terms like 'so and so' and 'whatever' but couldn't find anything that seemed relevant. Does anyone have some helpful links that might get me unstuck?"

As for your problem, I suggest you search for "Java tail utility" -- I've even made that an easy-to-click link for you. Good luck.
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It really helped with some minor changes for my need.
 
Junilu Lacar
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. Glad that helped.
 
Marshal
Posts: 67344
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arriving late: please do not put any Java code in a JSP. That is a very poor practice that has been discredited and obsolete for over 12 years now. 12 years!

For learning the proper way to structure Java web apps, please see this article.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!