Skip to content
Advertisement

Read integers from a text file and store them into an array in Java

So I have a text file with integers in it like this:

JavaScript

How can I read the file with above integers and store them into an array starting with 20 and ending with 10.

Advertisement

Answer

You can use java’s file nio.file api to read file data into string and then split that string using space to String[] and convert each number from String to an int in this array.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement