It's been awhile since I've created and written to a file. I've created the file and I've written to it but I get some weird characters. The only numbers that should be in the file are -1, 0, and 1.
Now I get the numbers I need, but I need them to displayed as a 2d array in the text file.
Example:
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
Please help
public void saveFile()
{
String save = "Testing";
JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
FileWriter bw = new FileWriter(fc.getSelectedFile()+".txt");
for(int row = 0; row < gameArray.length; row++)
{
for(int col =0; col < gameArray[row].length; col++)
{
bw.write(String.valueOf(gameArray[row][col]));
}
}
bw.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
ints then you need to convert to aString. If not, then you can use aDataOutputStreamto write the 4-byteintvalue.