I am trying to create a 2d array of size [3] and [100] the idea being it will store three strings which will be stored in a text file separated by tab. I have scoured the web for any help with this but failed to find any good answer. It needs to be an Array that it is stored in through Java.
It should be something like this:
- associates the String File with filename.txt
- create a 2d Array size 3 colums and 100 rows. here it should store the data from left to right with 3 strings on every line then seperated onto new lines.
- then I need a way to add the string in the text file to the array. and at the end it should println the contents of the array.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class ArrayDirectory {
public static void main(String args[]) {
String file = ("directory.txt");
// initialises the file linked to the String file
String[][] Entry = new String[3][50];
// creates a 2d array with 3 columns and 50 rows.
readFromFile.openTextFile(file);
//should read from file
String line = readFromFile.readLine();
int count = 0;
while (line != null) {
input[count] = String.split("");
Entry = readFromFile.readline();
}
for (int h = 0; h < input.length; h++) {
System.out.println(input[h]);
}
}
}
readFromFileandinputinitialised?