streamtokeniser ? how to

hi ,
I have some records in file like this

$$$$$ INFORMATION RECORD $$$$$
name1=value1
name2=value2


$$$$$ RECORD $$$$$
name=value
name=value


$$$$$ RECORD $$$$$
name=value
name=value

I want to strip off the header and put the 'name=value' for all records except the Information record to another file.
Can ypu please help! I can't understand streamtokenizer class at all,it complicated !
please tell me fast as I have to give it right now and i am still finding .

Thank you
hey_heyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rainmalCommented:
post code...
0
rainmalCommented:
post code...
0
rainmalCommented:
Heres some working code maybe you'd like to try out.

I hope I'm not working on you school assignments here!


import java.io.*;

public class Parser
{
      static
      {
            try
            {
                  PrintStream f = new PrintStream(new FileOutputStream("c:/log.log"),false);
                  System.setOut(f);
                  System.setErr(f);
            }
            catch(Exception e)
            {}
      }
      
      static StreamTokenizer st=null;
      static String newLine="\n";
      static boolean isFirst=true,isInfo=false;
      static String RECD="$$$$$ ";
      static String INFORMATION="INFORMATION";
      static StringBuffer strBuff=new StringBuffer();
      static String token=null;
      
      public static void main (String[] args)throws Exception
      {
        try
        {
                  //DataInputStream din=new DataInputStream(new FileInputStream(args[0]));
                  DataInputStream din=new DataInputStream(new FileInputStream("c:/sample.txt"));
                  byte [] data=new byte[din.available()];
                  din.readFully(data);
                  din.close();
                  
                  String dataStr=new String(data);                  
                  StringReader br=new StringReader(dataStr);
                  st = new StreamTokenizer(br);
                  
                  st.resetSyntax();
                  st.eolIsSignificant(false);
                  st.wordChars(32,126);
                  st.slashSlashComments(false);
                  st.slashStarComments(false);

                  String record=null;
                  
                  while((record=getTokens())!=null)
                  {
                        System.out.println("Record='\n"+record+"'");
                  }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
      }
      
      public static final String getTokens()throws Exception
      {
            strBuff.setLength(0);
        int tok=0;            
            
        while((tok = st.nextToken()) != StreamTokenizer.TT_EOF)
        {
            if(tok == StreamTokenizer.TT_WORD)
                  {
                        token=st.sval;

                        if(!isInfo)
                        {
                              if((token.indexOf(RECD)!=-1)&&(token.indexOf(INFORMATION)!=-1))
                              {
                                    isInfo=true;
                                    continue;
                              }

                              if(!token.startsWith(RECD))
                              {
                                    strBuff.append(token+newLine);
                              }
                              else if(!isFirst)
                              {
                                    break;
                              }
                              else if(isFirst)
                              {
                                    isFirst=false;
                              }
                        }
                        else if((token.indexOf(RECD)!=-1)&&(token.indexOf(INFORMATION)==-1))
                        {      
                              isInfo=false;
                              isFirst=false;                              
                        }
                        
                        token=null;
                  }
        }

            if(strBuff.length()==0)
            {      
                  return null;                  
            }
            else
                  return strBuff.toString();
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hey_heyAuthor Commented:
thansk you ,it worked perfectly and it's not homework!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.