Results 1 to 1 of 1
Thread: File I/O with DataOutputStream
- 12-16-2007, 10:39 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
File I/O with DataOutputStream
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:
PHP Code: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
Similar Threads
-
count character in text file as input file
By aNNuur in forum New To JavaReplies: 7Last Post: 03-25-2010, 05:01 PM -
File fp = new File(filePath);fp.exists() does not yeild proper result
By ganeshp in forum Advanced JavaReplies: 2Last Post: 04-07-2009, 07:25 AM -
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 10:13 AM -
Converting text file(.txt) to JPG file(.jpg) in java
By javadeveloper in forum Advanced JavaReplies: 0Last Post: 11-09-2007, 05:22 PM -
Regarding conversion of Image file to Video file
By RamaDeviMsc in forum Advanced JavaReplies: 0Last Post: 06-25-2007, 03:28 PM
Bookmarks