I'm reading from a text file a word (program) and I want to store it into my 2d array called word1. To do this, I read in the file and store into a placeholder array. I then convert this placeholder array into a char array so that every letter is split up. I now want to send the individual letter from this char array back to the string array (word1) that I created earlier. Ultimately, I want the word1 array to become like this
String word1[][] = {
{"p", "*"}, {"r", "*"}, {"o", "*"}, {"g", "*"}, {"r", "*"}, {"a", "*"}, {"m", "*"},
};
Everything works up until the very last bit where I try to convert the individual letters from the char array back into the word1 array.
FileReader file = new FileReader("C:/Users/Mark/Desktop/Java/Workshop 2/hangman.txt");
BufferedReader reader = new BufferedReader(file);
String text = "";
String line = reader.readLine(); //Keeps reading line after line
while (line != null){
text += line;
line = reader.readLine();
}
String word1[][] = {
{"", "*"}, {"", "*"}, {"", "*"}, {"", "*"}, {"", "*"}, {"", "*"}, {"", "*"},
};
String placeholder[] = text.split("\\s+"); //Converts text into an array
String s = "";
for (String n:placeholder){
s+= n;
}
char[] charArray = s.toCharArray();
for (int i = 0; i < 6; i++){
word1[i][0] = new String(charArray[i]); //This is where problem occurs
}