Solved

Java File I/O problem

Posted on 2003-11-02
5
253 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:daskino12
  • 3
  • 2
5 Comments
 

Author Comment

by:daskino12
ID: 9668277
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
0
 
LVL 5

Accepted Solution

by:
lwinkenb earned 250 total points
ID: 9668284
change:

while (din.available != 0)
{
          temp.concat(din.readLine());
}

to
String line;
while((line = din.readLine()) != null)
  temp += line;

and change:
String[] strArray = new String(st.countTokens())
to
String[] strArray = new String[st.countTokens()];

0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 9668286
also change your temp declaration to:
String temp = "";
0
 

Author Comment

by:daskino12
ID: 9668309
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
0
 

Author Comment

by:daskino12
ID: 9668321
Hello,

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
Weekend adv creator 3 38
Spring Framework HTTPSession management 1 33
servlet  URL Rewriting 1 36
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question