Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 211
FileInputStream and StringTokenizer

Hello,
Here is my code, when I try to compile it, I get an error.
Code:
Public void method2(String s)
{
 ...
}
 Public void method(String filename)
{		
		BufferedReader buff =new BufferedReader(
         new InputStreamReader(
         new FileInputStream(fileName)));
   while ((strparse = buff.readLine())!=null)
     {
     	method2(strparse);
     }        
}
}
I think there is a problem in the input stream. How to use the FileInputStream and the StringTokonizer. Any help on this will be highly appreciated. Thanks in advance.

Last edited by Logan 2 : 28-01-2010 at 12:40 PM.
Reply With Quote
  #2  
Old 28-01-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: FileInputStream and StringTokenizer

Hello,
I have read your code and I have done some modification, just check if the program run now and is successfully compiled.
Code:
Public Myclass
{
String strparse;
Public void method2(String s)
{
 ...
}

Public void method(String filename)
{
		try
{
		BufferedReader buff =new BufferedReader(
         new InputStreamReader(
         new FileInputStream(fileName)));
     while ((strparse = buff.readLine())!=null)
     {
     	method2(strparse);
     }        
}catch(Exception e)
{};
}
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: FileInputStream and StringTokenizer

Hi,
Thanks for your reply. I tried and it works, except instead of putting the following line of code in my program
Quote:
try{}
catch(Exception e)
can i include the following line in my program
Quote:
try{}
catch(IOException e)
I do not have much idea about the both, that is I do not have much idea abou the differences between them.
Reply With Quote
  #4  
Old 28-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: FileInputStream and StringTokenizer

Hello,
Before the nextToken() you have to verify if an element with has MoreTokens()
Code:
StringTokenizer strtok = new StringTokenizer("this is a test");
         while (strtok.hasMoreTokens()) {
             System.out.System.out.println(strtok.nextToken());
         }
The preceding code gives as result
Quote:
this
is
a
test
Reply With Quote
  #5  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: FileInputStream and StringTokenizer

Hi,
After a lot of efforts, I have arrived with the code, please check whether it is correct.
Code:
class Test
{
...
 
Public void parseLine(String line)
{
 StringTokenizer strtok = new StringTokenizer(row);
  	
 while (strtok.hasMoreTokens()) 
 {
  if(strtok.nextToken().equals("T1"))
  {
    t1.addlastrtok(new T1());
    motParse = strtok.nextToken();
    t1.getLast().nomType= motParse;

    motParse = strtok.nextToken();
    t1.getLast().idType= Integer.parseInt(motParse);
  }
  else . 
 }
}
Reply With Quote
  #6  
Old 28-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: FileInputStream and StringTokenizer

Hey,
I think you are mistaken here.
Code:
par = st.nextToken ();
t1.getLast (). nomType = par;
par = st.nextToken ();
you called nextToken() twice, that is two times in your code with testing the code. If you had tested the code then you would get an error. Hope you will correct your code and run it successfully.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "FileInputStream and StringTokenizer"
Thread Thread Starter Forum Replies Last Post
Problem in StringTokenizer Miles Runner Software Development 5 18-02-2010 04:43 AM
Retrieve an array using StringTokenizer Miles Runner Software Development 5 16-02-2010 12:57 AM
Problem with StringTokenizer Gunner 1 Software Development 5 07-02-2010 01:47 AM
Encoding and FileInputStream TechGate Software Development 5 25-01-2010 02:17 PM
FileInputStream Problem with UTF-8 Remedy Software Development 5 20-01-2010 11:19 AM


All times are GMT +5.5. The time now is 01:31 AM.