68 774
Assignments Done
Successfully Done
In January 2019

Answer to Question #66138 in Java | JSP | JSF for ebraheem

Question #66138
i want to take inputs from a text file to arrays to use later in the program
i tried this but i always get a null output
String[] anArray;
anArray = new String[10];
Scanner input = new Scanner(file).useDelimiter(" ");
while (input.hasNext()) {
if (input.equals("Add_Emp_Name")) {
for (int i = 0; i > 10; i++) {
anArray[i] = input.next();
Expert's answer
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class HelloWorld
public static void main(String[] args) throws IOException

BufferedReader fileBuffer = new BufferedReader(new FileReader("file.txt"));
String sentence = fileBuffer.readLine();
String[] arrayString = sentence.split(" ");
int[] arrayNumber = new int[arrayString.length];

for (int i = 0; i < arrayString.length; ++i)
arrayNumber[i] = Integer.parseInt(arrayString[i]);


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions