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();
}
}
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!
Learn more about our help with Assignments:
JavaJSPJSF