I have a data file, with each line having one number, like
10
20
30
40
How do I read this file and store the data into an array?
So that I can conduct some operations on this array.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just reading the file into an array, one line per element, is trivial:
Now the lines of the file are in the array
@lines.If you want to make sure there is error handling for
openandclose, do something like this (in the snipped below, we open the file in UTF-8 mode, too):