Hi - I have searched through the forum but couldn't find an answer to this, so if there already is one, please direct me! I am using FileWriter and DataOutputStream to write the contents of a JTable to a text file that is tab separated, but I can't figure out how to get it to go to the next line, it understands "\t" but not "\n". Any help would be much appreciated, here is my code so far:
public void saveFile() {
File file = null;
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory (new File ("."));
int result = fc.showSaveDialog (this);
if (result == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
if (file.exists ()) {
int response = JOptionPane.showConfirmDialog (null,
"Overwrite existing file?","Confirm Overwrite",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
FileOutputStream fos;
DataOutputStream dos;
try {
fos = new FileOutputStream(file);
dos = new DataOutputStream(fos);
for (int i = 0; i < data[0].length; i++){;
dos.writeChars(table.getValueAt(i,0).toString().trim());
dos.writeChars("\t");
dos.writeChars(table.getValueAt(i, 1).toString().trim());
dos.writeChars("\t");
dos.writeChars(table.getValueAt(i, 2).toString().trim());
dos.writeChars("\t");
dos.writeChars(table.getValueAt(i, 3).toString().trim());
dos.writeChars("\t");
dos.writeChars(table.getValueAt(i, 4).toString().trim());
dos.writeChars("\t");
dos.writeChars(table.getValueAt(i, 5).toString().trim());
//this is where i want code to go to the next line
} // end for
} // end try
catch (IOException e) {
System.err.println(e.getMessage());
} // end catch