function inside

void test(String gradeIn, String gradeOut)
{
FileWriter fw = null;
FileReader fr = null;

String tempString;
String [] tokenContainer = {"","0","0","0","0"};

try //try to catch FileNotFoundException
{
fr = new FileReader(gradeIn);
BufferedReader br = new BufferedReader(fr);

try // try to catch IOException
{
fw = new FileWriter(gradeOut);
BufferedWriter bw = new BufferedWriter(fw);

tempString = br.readLine();
while(tempString != null) //read the whole file until there is exception
{
tempString = tempString.trim();
if(!tempString.equals(""))
{
StringTokenizer st = new StringTokenizer(tempString);
int i = 0;
while(st.hasMoreTokens())
{
tokenContainer[i] = st.nextToken();
i++;
}

double sum = 0;
try // number format
{
for(int k = 1; k sum += Double.parseDouble(tokenContainer[k]);
}//try number format
catch (NumberFormatException nfe) {}// donothing

int average = (int)Math.round(sum/(tokenContainer.length - 1)*10);
bw.write(tokenContainer[0] + " " + average/10.0);
bw.newLine();
}
tempString = br.readLine();
} //while
bw.close();
fw.close();
br.close();
fr.close();
} //try
catch (IOException ioe)
{
//infoWindow.setText("Error in Reading File.");
}
}
catch(FileNotFoundException fnfe)
{ }
}

請您先登陸,再發跟帖!