Results 1 to 20 of 395
Thread: [SOLVED] Read From LOGFILE
- 05-24-2008, 01:28 PM #1
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 05-24-2008, 01:44 PM #2
Here are some examples,
orJava Code:void ReadFile(File f) throws Exception { Scanner scan=new Scanner(f); while(scan.hasNext()){ System.out.println(scan.next()); scan.next(); }scan.close(); }
I haven't test it yet, try it....Java Code:void ReadFile(File f) throws Exception { Scanner scan=new Scanner(f); while(scan.hasNextLine()){ System.out.println(scan.nextLine().split(" ")[0]); }scan.close(); }freedom exists in the world of ideas
- 05-24-2008, 02:23 PM #3
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Read From LOGFILE
i use both code in my programm.But out put is,It is printing may time.As i say i want to print only one time..
Plz help me
- 05-26-2008, 06:42 AM #4
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Plz help me any one
- 05-26-2008, 06:47 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you get all numbers, with duplicates.
- 05-26-2008, 07:02 AM #6
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 05-26-2008, 07:24 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, now what you can do is, store them in a list and add one by one. Before adding the element check it's exist or not.
- 05-26-2008, 07:27 AM #8
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
can you give me code of store in list and add one by one
- 05-26-2008, 07:30 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-26-2008, 07:31 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, here is a way to do it.
Java Code:import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; /** * * @author Eranga Tennakoon */ public class FileRead { private ArrayList<String> str; public FileRead() { this.str = new ArrayList<String>(); } private void getFileInfor(File myFile) { try { Scanner fileScanner = new Scanner(myFile); while(fileScanner.hasNextLine()) { doProcessing(fileScanner.nextLine()); } } catch (FileNotFoundException ex) { System.out.println(ex.getMessage()); } printResult(); } private void doProcessing(String strr) { String newStr = strr.split(" ")[0]; removeDuplicates(newStr); } private void removeDuplicates(String s) { if(str.isEmpty()) { str.add(s); } else { for(int i = 0; i < str.size(); i++) { if(!str.contains(s)) { str.add(s); } } } } private void printResult() { for(int i = 0; i < str.size(); i++) { System.out.println(str.get(i)); } } public static void main(String[] args) { File dd = new File("files/mir_001.txt"); new FileRead().getFileInfor(dd); } }
- 05-26-2008, 07:32 AM #11
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
yaa i got it.it's good if it working..
- 05-26-2008, 07:34 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Try an let me know is it work. ;)
- 05-26-2008, 07:50 AM #13
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
it is not working accourding to you and me.It is simply print all string which is present in log file..
- 05-26-2008, 07:52 AM #14
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Thxs for code but it's out put like this
And i want to show only one timeJava Code:192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9
i mean all duplicate 192.158.5.9 don't want to show.Java Code:192.158.5.9
plz help me
- 05-26-2008, 07:56 AM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No you are wrong, it's perfectly work for me. I don't know what happened in your end.
- 05-26-2008, 07:57 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-26-2008, 08:00 AM #17
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
plz see me log formate then try to run
- 05-26-2008, 08:01 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Are you talking about this.
Java Code:192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9 192.158.5.9
- 05-26-2008, 08:07 AM #19
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
yes
Java Code:192.158.5.9 kjnkjnkn 192.158.5.9 kasasdas 192.158.5.9 asdsad 192.158.5.9 sadasdsad 192.158.5.9 sadsad 192.158.5.9 rtertre 192.158.5.9 rtret 192.158.5.9 cbvv 192.158.5.9 cvbnghh 192.158.5.9 fghfgn 192.158.5.9 tyty
- 05-26-2008, 08:17 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, you get all of them as output. Reason is this.
The way of formated you log file and the way it handle on the code is not compatible. On a single line, number split depend on a single character space.
But in your log file there is no space. I can see tab, in some lines more than one tab. So what happened is all are counted as not duplicated on each.Java Code:String newStr = strr.split(" ")[0];
So, you get the output as
Because no one is similar to each other.Java Code:192.158.5.9 kjnkjnkn 192.158.5.9 kasasdas 192.158.5.9 asdsad 192.158.5.9 sadasdsad 192.158.5.9 sadsad 192.158.5.9 rtertre 192.158.5.9 rtret 192.158.5.9 cbvv 192.158.5.9 cvbnghh 192.158.5.9 fghfgn 192.158.5.9 tyty
Similar Threads
-
Must Read.....
By sanjeevtarar in forum Forum LobbyReplies: 10Last Post: 03-03-2010, 07:16 PM -
how to read a form with JFS
By crispy in forum JavaServer Faces (JSF)Replies: 2Last Post: 05-01-2008, 03:07 PM -
Read file
By tajinvillage in forum Threads and SynchronizationReplies: 0Last Post: 01-29-2008, 09:10 AM -
How to read the following
By rrp in forum New To JavaReplies: 0Last Post: 12-03-2007, 06:16 PM -
read txt file
By sureshsri1981 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-05-2007, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks