日期:2014-05-20 浏览次数:20661 次
package demo1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class AVGStream {
public static void main(String[] args) {
try{
File file=new File("F:\\aa.txt");
FileInputStream fis=new FileInputStream(file);
InputStreamReader is=new InputStreamReader(fis);
BufferedReader br=new BufferedReader(is);
String line=null;
int n = 0;
double total = 0;
while((line=br.readLine())!=null)
{
total+=Integer.parseInt(line);
n++;
}
double avg=(total/n);
System.out.println(avg);
}
catch(Exception ex)
{}
}
}
total+=Integer.parseInt(line);这行代码改为
total+=Integer.parseInt(line.trim());看一下行不