Link to home
Start Free TrialLog in
Avatar of daskino12
daskino12

asked on

Java File I/O problem

Hello,

I am trying to read in all the data from a file and return it in an array of the appropriate type.
Here is my code but i always get the following error:

cannot resolve symbol
symbol  : variable available
location: class java.io.BufferedReader
        while (din.available != 0)

Here is my code:

public static String[] readAllStrings ( String filename )
      throws FileIOException
{
      try {
      String temp;
      int j = 0;
      
      FileInputStream fin = new FileInputStream(filename);
      BufferedReader din = new BufferedReader(new InputStreamReader(fin));
      
      while (din.available != 0)
      {
            temp.concat(din.readLine());
      }
      
      StringTokenizer st = new StringTokenizer(temp);
      
      String[] strArray = new String(st.countTokens());
      
      
      while(st.hasMoreTokens()){
            strArray[j] = st.nextToken();
            j++;
      }
      
      
      }
      catch (IOException e)
      {
      }
      
}


Please help.

Thanks

PS:  This is my assignment.
Avatar of daskino12
daskino12

ASKER

Hello,

I am sorry but I have one more error:

cannot resolve symbol
symbol  : constructor String (int)
location: class java.lang.String
        String[] strArray = new String(st.countTokens())

THanks
ASKER CERTIFIED SOLUTION
Avatar of lwinkenb
lwinkenb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also change your temp declaration to:
String temp = "";
Hello,

Thanks but now i got the following errors:

illegal start of expression
        while(line = din.readLine()) != null)
and

incompatible types
found   : java.lang.String
required: boolean
        while(line = din.readLine()) != null)


Thanks
Hello,

I am sorry.  My bad.  It works.  Thank you very much.