File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Does anyone know how to read a log file in .log and output the data using java language ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Does anyone know how to read a log file in .log and output the data using java language ?

motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Does anyone know how to read a log file in .log and output the data using java language ?
Please help me !!!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

What do you mean? What is ".log"? is that a language? a file format? Why can't you read it like any other file in java?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mazer Lao Tzu
Ranch Hand

Joined: Jan 20, 2010
Posts: 35
".log" is simply a common file extension indicating that a particular file serves as a log for a particular application. Most likely these files are written in ASCII, but the format in which they represent data is entirely dependent on the application that wrote the file.
What application wrote the file?



-- Mazer
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
fred rosenberger wrote:What do you mean? What is ".log"? is that a language? a file format? Why can't you read it like any other file in java?


It is a text file with the extension .log which contains data inside.
Where can i find the coding to read the data in .log file and display it ?
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
If it is just a plain text file with a .log extension, you should just be able to use the same code that you would use to read a regular .txt file.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Mazer Lao Tzu wrote:".log" is simply a common file extension indicating that a particular file serves as a log for a particular application. Most likely these files are written in ASCII, but the format in which they represent data is entirely dependent on the application that wrote the file.
What application wrote the file?

Accuatly the log file is created using placelab (an open source to detect wireless signal). Its detect all wireless ap signal strength in a particular area and save it in log file.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is there any reason to display it with Java? Can't you just use the command line or an editor?
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
TYPE=TIMEOUT
TYPE=WIFI|TIME=1263867778390|ID=00:24:c3:31:2b:e0|NAME=csusm|RSSI=-93|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:12:17:7b:33:04|NAME=csusm|RSSI=-80|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:1f:27:55:f7:70|NAME=USMHotspot|RSSI=-70|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:1e:13:ee:3e:40|NAME=USMHotspot|RSSI=-85|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:24:c3:31:b8:80|NAME=csusm|RSSI=-91|WEP=true|INFR=true


The above is part of the log file data which contain the type of wireless ap, time detected, Id, name of wireless ap, signal strength and so on.
But i just want to read the signal strength, count the signal average and display it.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

Can you write a java program to open and read any file? There is nothing special about it being a '.log' file.

[edit]
So now we're getting what you really want. You still need to be able to do the above. I'd suggest you write a program that reads each line and prints it out first. Once you have that, you can start looking at parsing the data. The best way to do this is by writing a little piece at a time.

motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
fred rosenberger wrote:Can you write a java program to open and read any file? There is nothing special about it being a '.log' file.

[edit]
So now we're getting what you really want. You still need to be able to do the above. I'd suggest you write a program that reads each line and prints it out first. Once you have that, you can start looking at parsing the data. The best way to do this is by writing a little piece at a time.



Now i can read the file and display it. Thank to all.
But the problem i faced now is how am i gonna just read the signal strength RSSI ? I don wan to display other info, just want to display the signal strength.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Check out String.split, but take into account that | means something special when used as an argument to String.split.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

you could also find where in the string "RSSI" is, and then you can grab the 2-character substring just a few places after that...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Ehm, that's not necessarily 2 characters. It may also be 3, like -90.

You do have a point however. Using indexOf you can first find where RSSI= starts, and advance to the end of that. Next find the next |, and take the substring in between.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

since all the examples had the '-', it didn't matter. but that is a good point. Could you have 3-digit or 1-digit values? or 4-digit?

the larger point is there is more than one way to do it.
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
fred rosenberger wrote:since all the examples had the '-', it didn't matter. but that is a good point. Could you have 3-digit or 1-digit values? or 4-digit?

the larger point is there is more than one way to do it.


largest is 3 digit such as -90 .
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Rob Prime wrote:Ehm, that's not necessarily 2 characters. It may also be 3, like -90.

You do have a point however. Using indexOf you can first find where RSSI= starts, and advance to the end of that. Next find the next |, and take the substring in between.


But the indexOf() is just use to show the location of the character and printout the location number.
How can i make it to take the -90 and print it out ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

motress zlting wrote:
But the indexOf() is just use to show the location of the character and printout the location number.
How can i make it to take the -90 and print it out ?


As mentioned on your other (somewhat duplicate) topic...

http://www.coderanch.com/t/481595/Java-General/java/using-indexOf-just-take-RSSI

There are other methods of the java.lang.String class, that can help you here.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

The best way to figure out how to code it is to write out how you would do it by hand.

Say you were going to hand a piece of paper to someone with this data on it. They don't know what ANY of this stuff means, what's relevant and what's not.

How would you tell them to find the specific piece of data you want from each line?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does anyone know how to read a log file in .log and output the data using java language ?
 
Similar Threads
Javamail MimeMessage.writeTo(..)
Monitoring File System
How to redirect Tomcat's console output into a log file?
MSSQL and Unicode in WIndows and Linux
Does anyone know how to write contour using java language ?