简体   繁体   English

如何将文本文件存储到数组 <double> 使用Double.parseDouble(string s)方法

[英]How to store a text file to an Array <double> using the Double.parseDouble(string s) method

I have text file called numbers2.txt that I need to store into an ArrayList<Double> using the Double.parseDouble(string s) method. 我有一个名为numbers2.txt的文本文件,需要使用Double.parseDouble(string s)方法存储到ArrayList<Double> I have no idea on how to do this. 我不知道该怎么做。

Here is what I have so far. 这是我到目前为止所拥有的。

import java.util.Scanner;

public class Operator {
    public void createArrayList() {
        String[] math = {"add ", "Subtract ", "multiply ", "divide ", "remainder ", "Greaterthan ",
                "lessthan ", "max ", "min ", "power"};
        Scanner file = new Scanner("data\numbers2.txt");
    }
}

The text file includes: 1 2 3 4 5 6 7 8 9 10 文本文件包括:1 2 3 4 5 6 7 8 9 10

Any help would be appreciated, thank you. 任何帮助,将不胜感激,谢谢。

You can use BufferedReader to load the file. 您可以使用BufferedReader加载文件。

BufferedReader br = new BufferedReader(new FileReader("<Filename>"));

After loading the file, you can store the value from text file to a String variable line by line. 加载文件后,可以将文本文件中的值逐行存储到String变量中。

String line = br.readLine();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM