Current location: Hot Scripts Forums » Programming Languages » Everything Java » how to read file in csv format in java n find word using tokenizer


how to read file in csv format in java n find word using tokenizer

Reply
  #1 (permalink)  
Old 10-28-06, 08:18 AM
mizfifa mizfifa is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
how to read file in csv format in java n find word using tokenizer

konnichiwa..

i try to find a word from .php file. Basically, i try to read from any text file too..

firstly, i need to read file from .php file.
This is one of example word: echo welcome
then, try to find n match (using string tokenizer) with database file that i created in text file using csv format. Can anyone give a suggestion n sample about it..
Reply With Quote
  #2 (permalink)  
Old 10-28-06, 12:33 PM
reportingsjr reportingsjr is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Just so you know you cant view the php source. It gets generated into client side code. So you couldnt do that. But for the text file check out regular expressions .
Reply With Quote
  #3 (permalink)  
Old 10-28-06, 01:19 PM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
StringTokenizer st = new StringTokenizer (search_this_string, "echo welcome");
 
while (st.hasMoreTokens ())
{
      //your code here
}
search_this_string would be replaced with the string you are searching in.
__________________
my site
Reply With Quote
  #4 (permalink)  
Old 11-04-06, 06:44 PM
mizfifa mizfifa is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
scan file

actually, i try to read php file. i got some php codes from open source software like osCommerce n others..

i found some codes for greet customer, as a keyword that i want to search..
then, i keep all codes or keyword in 1 file - criteria.csv.. tha's ok, i dont need read by using csv format.. i like to read in a simple way in java..
java also can read this file,right.

process-

1-i read file.php line by line n pass
2-then, i need to check that php file match n have a keyword from criteria.csv file..
3-as a result, the found keyword will be display

************************************************** *******
my criteria.csv file look like,

criteriaID,criteriaName, criteriaType, criteriaDesc, criteriaScore
bookmarkdelete(), link personalization,explicit,function delete bookmark ,2
echo tep_customer_greeting( ),anthropomorhic,implicit,display welcome using function greeting customer,1

************************************************** *******

my fren told me to use column and rows with an array.. i juz want to scan for criteriaID only.. like bookmarkdelete() n echo tep_customer_greeting( ) do u have any suggestion..
Reply With Quote
  #5 (permalink)  
Old 11-04-06, 08:14 PM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
criteria.csv
You can read this file line by line, parse through and store each item to search for in an array. After that, read file.php line by line while using indexOf to check for the occurance of any items stored in the searchArray (use looping to do this). If indexOf returns something greater than zero, then you have a match.
__________________
my site
Reply With Quote
  #6 (permalink)  
Old 11-04-06, 11:52 PM
mizfifa mizfifa is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
urm, i can't see how it is. can u give me a sample how to code this..
Reply With Quote
  #7 (permalink)  
Old 11-05-06, 07:00 AM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mizfifa
urm, i can't see how it is. can u give me a sample how to code this..
show some effort first.
__________________
my site
Reply With Quote
  #8 (permalink)  
Old 11-06-06, 06:54 PM
mizfifa mizfifa is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
uhm, how it is..

Code:
  
else if (e.getSource() == btnScan)
{
                        
          //read criteria.csv file

      int rowData=16;//not fixed data actually,because the data can be update
    
     File criteria_file = new File("criteria.csv");
     String [][] phpKeyword = new String[rowData][5];

    
    try 
    {
     BufferedReader bufRdr = new BufferedReader(new FileReader(criteria_file));
       String line = null;
        
       int row=0;
    
    
       while((line = bufRdr.readLine()) != null)
        {
            StringTokenizer st = new StringTokenizer(line,",");

             while (st.hasMoreTokens())
            {
                int column=0;
            
                while(column<5)
                 {
               
                   phpKeyword[row][column]=st.nextToken();
                   System.out.println("Token = " + phpKeyword[row][column]);
                  column++;
                 }
        
                  row++;
             }
        
            }
    
          bufRdr.close();
    
        }
      
               
     
                
      //read php file from selected folder

       for(rowData=0;rowData<16;rowData++)
       {    int column=0;int row=0;
            
            for(column=0;column<5;column++)
            {
                 String search_this_string = phpKeyword[row][column];
                 
                 File PHPdirectory = new File(phpFile.getPath());
                    
                if(PHPdirectory .isDirectory() == true)
                 { 
                    String[] files = PHPdirectory.list(); 
                    System.out.println("Files in directory \"" + PHP + "\":");
                        
                    for (int i = 0; i < files.length; i++)
                    {
                     System.out.println("   " + files[i]);
                       
                      int num_lines = 0;
                      try 
                      {
                       // Create a FileReader and then wrap it with BufferedReader

                       FileReader file_reader = new FileReader (files[i]);
                      BufferedReader buf_reader = new BufferedReader (file_reader);
                                
                   // Read each line of the file and look for the string of interest.
                      do 
                       {
                        String line = buf_reader.readLine ();
                        if (line == null) break;
                       if (line.indexOf(search_this_string) != -1)  num_lines++;
                       } 
                      while (true);
                    buf_reader.close ();
                   }
                            
              catch (IOException e) 
              {
                  System.out.println ("IO exception =" + e );
              }
           System.out.printf ("Number of lines containing \"%s\"  = %3d %n",search_this_string, num_lines);
              }
         }    
                            
           /**else  
             {
               JOptionPane.showMessageDialog(null,"Wrong path","PAT",2);
              }  */
                    
       }   
                
     }
                     
  }

anyway, its hv an error.. highlight at catch--->
catch (IOException e)
{
//e.printStackTrace();
System.out.println ("IO exception =" + e );
}

--> e is already define in action performed

mybe the structure of code. should i use if else in anywhere.. can u check for me.. plz..
Reply With Quote
  #9 (permalink)  
Old 11-07-06, 05:39 AM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Okay, I see what's happening. You have previously declared a variable name 'e' and are trying to use it again. Since it says actionPerformed, I'm guessing you used the following declaration for the actionPerformed method:
Code:
void actionPerformed(ActionEvent e)
{
}
Where e is being used as the actionevent variable.

to fix just change the name of one of the variables (exception would be the easiest):

Code:
          catch (IOException ioe) 
              {
                  System.out.println ("IO exception =" + ioe.toString() );
              }
__________________
my site
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a file exists lee PHP 3 04-23-06 12:44 AM
Export Mysql to Excel mcrob PHP 8 07-12-05 06:49 AM
Database file or object file is read only, w_inaim ASP 2 09-21-04 02:18 PM
what is the best method to find last word in variable ? GS300 PHP 6 09-15-04 09:13 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 05:38 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.