从文件中读取数据到数组中 [英] Reading data into array from file

查看:111
本文介绍了从文件中读取数据到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是一名新的Java学习者。我想用Java开发一个模型。在该模型中,有许多文件需要阅读。我想用Java编写一个方法来读取文件并将数据存储在数组中。后来,我只是调用该方法来读取其他文件。你能不能帮我编写一个代码来读取以下格式的数据:

第一种格式(例如,用行分隔):将一列数据存储在一个数组中


11.1

22.2

33.3

...


第二种格式(例如,用空格分隔):将一列数据存储在一个数组中,因此有三个数组


1.1 11.1 111.1

2.2 22.2 222.2

3.3 33.3 333.3

...... ......

Hello, I am a new Java learner. I would like to develop one model by using Java. In that model, there are many files to read. I want to write a method in Java to read a file and store the data in array(s). Later, I just only call that method to read other files. Would you please help me to write a code to read the data in the following formats:

First format (for example, separated by lines): store one column of the data in one array

11.1
22.2
33.3
...

Second format (for example, separated by spaces): store one column of the data in one array, so there are three arrays

1.1 11.1 111.1
2.2 22.2 222.2
3.3 33.3 333.3
... ... ...

推荐答案


你好,我是一名新的Java学习者。我想用Java开发一个模型。在该模型中,有许多文件需要阅读。我想用Java编写一个方法来读取文件并将数据存储在数组中。后来,我只是调用该方法来读取其他文件。你能不能帮我编写一个代码来读取以下格式的数据:

第一种格式(例如,用行分隔):将一列数据存储在一个数组中


11.1

22.2

33.3

...


第二种格式(例如,用空格分隔):将一列数据存储在一个数组中,因此有三个数组


1.1 11.1 111.1

2.2 22.2 222.2

3.3 33.3 333.3

...... ......
Hello, I am a new Java learner. I would like to develop one model by using Java. In that model, there are many files to read. I want to write a method in Java to read a file and store the data in array(s). Later, I just only call that method to read other files. Would you please help me to write a code to read the data in the following formats:

First format (for example, separated by lines): store one column of the data in one array

11.1
22.2
33.3
...

Second format (for example, separated by spaces): store one column of the data in one array, so there are three arrays

1.1 11.1 111.1
2.2 22.2 222.2
3.3 33.3 333.3
... ... ...



您想使用一种方法来读取这两种类型的文件吗?

将值存储在ArrayList而不是Array中,这样您就不必首先找到文件中的行数。 br />

Do you want to use one method to read both types of files?
Store the values in ArrayList rather than an Array so you don''t have to find the number of lines in the files first.

展开 | 选择 | Wrap | 行号


感谢您的帮助和评论。如果可能,我想使用两种不同的方法来读取数据文件的两种不同格式。
Thanks for your help and comments. If possible, I would like to use two different methods to read the two different formats of the data files.



感谢您的帮助和评论。如果可能的话,我想使用两种不同的方法来读取数据文件的两种不同格式。
Thanks for your help and comments. If possible, I would like to use two different methods to read the two different formats of the data files.



你可以写下第二行

You could write the second one along the lines of

展开 | 选择 | 换行 | 行号


这篇关于从文件中读取数据到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆