Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-16-2007, 11:39 PM
Member
 
Join Date: Dec 2007
Posts: 2
Tzaphiel is on a distinguished road
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 0data[0].lengthi++){;    
            
dos.writeChars(table.getValueAt(i,0).toString().trim());
    
dos.writeChars("\t");
    
dos.writeChars(table.getValueAt(i1).toString().trim());
    
dos.writeChars("\t");
    
dos.writeChars(table.getValueAt(i2).toString().trim());
    
dos.writeChars("\t");
    
dos.writeChars(table.getValueAt(i3).toString().trim());
    
dos.writeChars("\t");
    
dos.writeChars(table.getValueAt(i4).toString().trim());
    
dos.writeChars("\t");
    
dos.writeChars(table.getValueAt(i5).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 
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read a text file from a Java Archive File Java Tip Java Tips 0 02-08-2008 11:13 AM
File fp = new File(filePath);fp.exists() does not yeild proper result ganeshp Advanced Java 1 12-27-2007 01:42 AM
Converting text file(.txt) to JPG file(.jpg) in java javadeveloper Advanced Java 0 11-09-2007 06:22 PM
Regarding conversion of Image file to Video file RamaDeviMsc Advanced Java 0 06-25-2007 04:28 PM
count character in text file as input file aNNuur New To Java 0 06-18-2007 08:46 AM


All times are GMT +3. The time now is 03:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org