I have this code,
else if (e.getSource() == saveButton) {
Scanner scan;
String es = " ";
try {
int status = chooser.showSaveDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
File newImageName = chooser.getSelectedFile();
PrintWriter outFile = new PrintWriter(new FileWriter(newImageName));
outFile.print(drawing.typefile);
outFile.print(drawing.iname);
outFile.print(drawing.width);
outFile.print(es);
outFile.print(drawing.height);
outFile.print(drawing.maxshade);
for(int r = 0; r < drawing.array.length; r++)
for(int c = 0; c < drawing.array[r].length; c++)
outFile.print(drawing.array[r][c]);
// outFile.print(drawing.paintComponent(newImageName));
outFile.flush();
outFile.close();
}
else if (status == JFileChooser.CANCEL_OPTION) {
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "File could not be written, try again.");
//ex.printStackTrace();
}
}
and how do i get it to print spaces in between the values?
it prints
P2image1.pgm320 275255132132130125125128
and i need it to print
P2image1.pgm320 275255132 132 130 125 125 128
hence there being a space in between each array value and i have tried a lot of stuff but i am thoroughly confused.
Thanks.
Just print a space after each number, explicitly.
Have you tried something like: