62,620
社区成员
发帖
与我相关
我的任务
分享
String str="hh\n1\n22\n798.809\n0.89\n";
String regex="\\d+(?:\\.\\d+)?";
Matcher m=Pattern.compile(regex, Pattern.MULTILINE).matcher(str);
List<String> result=new ArrayList<String>();
while(m.find()){
result.add(m.group());
}

private static boolean isWindowsOS() {
boolean isWindowsOS = false;
String osName = System.getProperty("os.name");
if (osName.toLowerCase().contains("windows")) {
isWindowsOS = true;
}
return isWindowsOS;
}
刚才你打的时候我正在结贴,没看到,还是要多谢哦[/quote]


package org.bklab.vaadin.io;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class ReadSingleLineNumber {
public ArrayList<Double> read() {
ArrayList<Double> numbers = new ArrayList<>();
BufferedReader br;
String filePath = "C:\\Users\\Broderick\\Desktop\\num.txt";
try {
br = new BufferedReader(new FileReader(filePath));
String s = br.readLine();
while (s != null){
try {
numbers.add(Double.parseDouble(s));
} catch (NumberFormatException ignore){}
s = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
if(numbers != null && numbers.size() > 0) {
numbers.forEach(d -> System.out.println(d));
}
return numbers;
}
public static void main(String[] args) {
new ReadSingleLineNumber().read();
}
}