Solved

Java File I/O problem

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 87
endX challenge 2 50
for i loop in grovy 1 32
compre toata in where clue oracle 4 44
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now