[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Java File I/O problem

Posted on 2003-11-02
5
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

650 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