I have an array of char
grid and I want to write a file with its contents. Here is the code I did:
public static String getGrid() {
String text = String.valueOf(grid);
return text;
}
public static void Escreve() {
String imprime = getGrid();
System.out.println(imprime);
File newFile = new File("C:/Users/Miguel/Desktop/newFile.txt");
if (newFile.exists()) {
System.out.println("já existe");
} else {
try {
newFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileWriter fileW = new FileWriter(newFile);
BufferedWriter buffW = new BufferedWriter(fileW);
buffW.write(imprime);
buffW.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The array grid
would originally look like this:
grid = {{'W','S','W', 'W'}, {'W','W','_','E'}}
The desired end result of the created file is:
WSWW
WW_E
The first "function" transforms the array from char to string array and the second creates a new file and should write the contents of the array, but what I get in the created file is as follows: [[C @ 2424d3cc < p>
Some way to solve the problem?