Arrays 如何使用JFileChooser从文本文件中获取双精度数字,并将其存储在Number类型的数组(具有对象类型的数组))中?
如果我有一个数字如下的文本文件: 25.1, 2.2, .02, .11, 11.5, 9.6, 等 我如何将所有这些存储在Number类型的数组中(例如,Number[]myArray)? 如何从文本文件将这些数字存储在myArray中 名为Number.txt的假设文本文件中的示例编号 .20 十一, 十三, 15.2 .02 .14 .15 .16 .78 .19 十四, 二十三 二十四 .18Arrays 如何使用JFileChooser从文本文件中获取双精度数字,并将其存储在Number类型的数组(具有对象类型的数组))中?,arrays,object,data-structures,text-files,Arrays,Object,Data Structures,Text Files,如果我有一个数字如下的文本文件: 25.1, 2.2, .02, .11, 11.5, 9.6, 等 我如何将所有这些存储在Number类型的数组中(例如,Number[]myArray)? 如何从文本文件将这些数字存储在myArray中 名为Number.txt的假设文本文件中的示例编号 .20 十一, 十三, 15.2 .02 .14 .15 .16 .78 .19 十四, 二十三 二十四 .18 public static void main(String[] args) throws I
public static void main(String[] args) throws IOException {
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
jfc.setDialogTitle("Coose a Directory.");
jfc.setAcceptAllFileFilterUsed(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT Files Only", "txt");
jfc.addChoosableFileFilter(filter);
int returnValue = jfc.showSaveDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
//System.out.println(selectedFile.getAbsolutePath());
String line = "";
BufferedReader br = new BufferedReader(new FileReader(selectedFile));
while((line = br.readLine()) != null){
/* Right Here.How do I store "selectedFile" into an array of type Number?*/
}
}
else {
System.out.println("File not located.");
}
}//end main