我有文件中的数据file.txt:1,2,3
我想总结所有的数据文本。应该如何继续?sum文件txt使用扫描仪java
int a[] = new int [5];
int h=0;
String fileName = "C:/Users/ASUS/Desktop/Numbers.txt";
File textFile = new File (fileName);
Scanner in = new Scanner (textFile);
while (in.hasNextLine())
{
String Line = in.nextLine();
System.out.println(Line);`enter code here`
}
for (int i = 0; i<a.length; i++)
{
h +=a[i];
}
in.close();
System.out.print("Sum is : " + h);
}
谢谢!
使用'nextInt()' – BLUEPIXY 2014-10-31 01:02:59