[英]How to read doubles from a .txt file
I'm able to read the string variables, but it won't read the double for some reason. 我能够读取字符串变量,但是由于某种原因,它不会读取double值。 What can I do to make it read the double? 我该怎么做才能使它读成两倍?
public class RundraiserApp
{
/**
* @param args
*
*/
public static void main(String[] args)
{
Fundraising[] dList = new Fundraising[10];
String name = null;
String address = null;
String cityStateZip = null;
double donation = 0;
int i = 0, ctr = 0;
Scanner in;
File file = new File("Donations.txt");
try
{
in = new Scanner(file);
while (in.hasNext() && i < dList.length)
{
name = in.nextLine();
address = in.nextLine();
cityStateZip = in.nextLine();
donation = in.nextDouble();
i++;
}
ctr++;
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
}
}
Considering your file structure below 考虑下面的文件结构
Name
Address
Zip
2000.50
Change donation like. 改变捐赠之类的。
donation = Double.parseDouble(in.nextLine());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.