this particular question is givin me a headache, can any1 help???
Using the countChars() method from the previous answer, write a method called fileSize() declared as follows:
public int fileSize (String name) {
...
}
which counts the number of characters in the file whose name is supplied as the "name" parameter. This method should return the number of characters in the file, or -1 if an IOException occurs.
Insert the code for your method in the space below:
Previous answer -
Using the countChars() method from the previous answer, write a method called fileSize() declared as follows:
public int fileSize (String name) {
...
}
which counts the number of characters in the file whose name is supplied as the "name" parameter. This method should return the number of characters in the file, or -1 if an IOException occurs.
Insert the code for your method in the space below:
Previous answer -
Code:
public int countChars(InputStream is) throws IOException
{
int count = 0;
BufferedInputStream bis = new BufferedInputStream(is);
while(bis.read() != -1)
{
count++;
}
return count;
}
Comment