Solved

Java File I/O problem

Posted on 2003-11-02
5
262 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jmss example java 2 34
Eclipse for Java EE development 2 46
IBM TS2900 (3572) Tape Autoloader Java? 12 61
Netbeans and org.apache.commons.lang3 issue 3 30
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

730 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