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();
}
}
1
Expert's answer
2017-03-13T11:46:06-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS