从文件中读取浮点数 [英] Read float numbers from file
本文介绍了从文件中读取浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从文件中读取浮点数?
How to read float numbers from file?
0.00000E+00 2.12863E-01
1.00000E-02 2.16248E-01
2.00000E-02 2.19634E-01
在文件中2第一列数字之前和数字之间的空格。我有错误:
in the file 2 spaces before the first column of numbers and between numbers. I have errors instantly:
s = new Scanner(new File("P0"));
while (s.hasNext()) {
float x = s.nextFloat();
float y = s.nextFloat();
System.out.println("x = " + x + ", y = " + y);
}
推荐答案
所以,我理解我的错误。我需要使用
So, I understand my mistake. I need to use
s.useLocale(Locale.US);
因为Scanner互换。作为小数分隔符,在我的语言环境中(默认)它是,。另请注意,根据
because that Scanner interpets "." as decimal separator, in my locale (default) it is ",". Also note that both 1.1 and 3 (integer) are recognized by nextDouble
//可识别1.1和3(整数)阅读 - 双数字 - 来自混合文件?rq = 1title =此链接>此链接
//according to this link
这篇关于从文件中读取浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文