好急啊!谁能帮我写一下这程序阿???感激不尽阿!!! write a program that will take numbers from a file called Numbers.txt and then add them up, and give out their average 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;public class ReadNumber { public static void main(String[] args) { File file = new File("number.txt"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); String temp; float sum = 0; int i = 0; while( (temp = br.readLine()) != null) { sum += Float.parseFloat(temp); i++; } System.out.printf("平均值为:%.2f%n", sum / i); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } }}number.txt内容:14.315.738.9145.9 额``为什么读取不到文本文件。。我把文本文件放在C盘File file = new File("number.txt");是不是该写成File file = new File("C:\number.txt"); ? 应该改写成 File file = new File("C:/number.txt"); 应用“/”或“\\”都可以。也可以不用写这句。把 br = new BufferedReader(new FileReader(file));改为: br = new BufferedReader(new FileReader("c:/number.txt"));也是一样的。 FileInputStream 问题 一道面试逻辑思维题 线程的创建 想不通 救命啊 java中如何获得当时的时间? 请问如何快速移动文件 有小问题 请高手指教 向高手求教:Swing中JTree的使用 那位大哥有java 的jdk 开发文档 。可以告诉我能在那找到么?(最好是中文的。谢谢) java代码压缩文件,文件名中中文变为乱码 求教关于Buff的操作 关于singleton pattern的问题
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;public class ReadNumber { public static void main(String[] args) {
File file = new File("number.txt");
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String temp;
float sum = 0;
int i = 0;
while( (temp = br.readLine()) != null) {
sum += Float.parseFloat(temp);
i++;
}
System.out.printf("平均值为:%.2f%n", sum / i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}number.txt内容:
14.3
15.7
38.9
145.9
我把文本文件放在C盘
File file = new File("number.txt");是不是该写成File file = new File("C:\number.txt"); ?
也可以不用写这句。
把
br = new BufferedReader(new FileReader(file));
改为:
br = new BufferedReader(new FileReader("c:/number.txt"));
也是一样的。