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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also change your temp declaration to:
String temp = "";
String temp = "";
ASKER
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
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
ASKER
Hello,
I am sorry. My bad. It works. Thank you very much.
I am sorry. My bad. It works. Thank you very much.
ASKER
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