//txt文件地址,我之前尝试过放进Maven项目中,在编译器没问题,但打包成jar包,地址找不到,有高人能实现的话,求指教.
//文本数据:
1,2,3,4,
5,6,7,8,
..
public Double[][] getlkmList(String materials) throws Exception{
int date =Integer.parseInt(materials.substring(6, 8));//日
Double[][] lkm=new Double[19][date];
String urlAddress = "C:\\xx\\xx.txt";
File file=new File(urlAddress);
if (!file.exists()){
file.createNewFile();
}
List<String> ids = Files.lines(Paths.get(urlAddress)).collect(Collectors.toList());
for(int i=0;i<ids.size();i++){
String temp1[] = ids.get(i).split(",");
int a=date-1;
for(int j=0;j<date;j++){
lkm[i][a]=new Double(temp1[j]);
a--;
}
}
return lkm;
}
将txt文本内数据转化为数组
于 2023-02-28 11:32:35 首次发布