I have turned a grid into a CSV format, which turns it into a string in order to save the grid.
However, when I want to open the CSV file, I have to turn the string back into a 2D array.. I have tried to work out how to do it, but I am unsure on how to join the two string[] so that it turns into a 2D array.
I added an ; where the line ends and a new line must begin, but I am confused about how to add it together.
The code:
public static void open() {
// The name of the file to open.
String name = JOptionPane.showInputDialog(null,
"Enter the name of the file you wish to open: ");
String fileName = name+ ".txt";
// This will reference one line at a time
String line = null;
char gridWorld[][];
try {
// FileReader reads text files in the default encoding.
FileReader fileReader = new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader = new BufferedReader(fileReader);
String[] firstsplit, secondsplit;
while ((line = bufferedReader.readLine()) != null) {
for(int i = 0; i < line.length(); i++){
firstsplit = line.split(";"); // if semi colon, replace with new line
}
secondsplit = line.split(","); // splitting the line in columns
}
// Always close files.
bufferedReader.close();
any help would be greatly appreciated.