Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 11-09-2004, 12:28 AM   #1 (permalink)
philthee
Registered User
 
Join Date: Oct 2004
Posts: 15
philthee is on a distinguished road
having trouble with writing to file

Hi there, i am havingg trouble getting my results written to file, seems to be just the last line that is written, probably overwriting each line as it goes through the loop rather than writing to a new line.
How do i fix this?


Code:
if (myCC.getBand(start_band_position)!=null) { chromosomeBand myCB = new chromosomeBand(myCC.getB and(start_band_position)); flpterRange myFLR = myCC.getFlpterRange(start_band _position); try { int cytcounter = 1; File cytotable = new File("/mnt/rinetapp1a/u sers/devallp/src/demoChromosomeStuff/cytogenetic-assignment-table.txt"); File probetable = new File("/mnt/rinetapp1a/ users/devallp/src/demoChromosomeStuff/probe-table.txt"); FileWriter fw = new FileWriter(cytotable); PrintWriter pw = new PrintWriter(fw); pw.print(cytcounter + " " + myFLR.getStar t() + " " + myFLR.getEnd() + " " + chromosome + " " + symbol); fw.close(); System.out.println("The symbol is " + symbol ); System.out.println("The chromosome is " + ch romosome); System.out.println("The band is " + myCB.get Name()); System.out.println("With a start value of " +myCB.getStart()); System.out.println("And an end value of " + myCB.getEnd()); // flpterRange myFLR = myCC.getFlpterRange(st art_band_position); System.out.println("The flpterrange seems to be from " + myFLR.getStart() + " to " + myFLR.getEnd()); cytcounter++; break; } catch (IOException e) { System.out.println("something wrong with io??"); }
the standard out prints all the results no problem but there is only ever one line of results that is printed to file.

how do i get the results printed to file to print to a new line each time rather than writing over each previous line?
I guess it has to do with when the filewriter is closed but i can't seem to put it anywhere else and if i remove it completely i get no results to file.
__________________
philthee is offline   Reply With Quote
Old 11-09-2004, 05:28 AM   #2 (permalink)
kaeli69
Registered User
 
kaeli69's Avatar
 
Join Date: Apr 2003
Posts: 30
kaeli69 is an unknown quantity at this point
The code is in a loop, from what I can tell from that break statement.
You're opening and closing the file IN the loop. Which opens for writing, not appending. So with each loop iteration, it overwrites the file.

Open and close the file somewhere else and just write to it in the loop.

HTH
__________________
kaeli69 is offline   Reply With Quote
Old 11-09-2004, 05:32 AM   #3 (permalink)
philthee
Registered User
 
Join Date: Oct 2004
Posts: 15
philthee is on a distinguished road
cheers, i eventually noticed that and have it working now.
__________________
philthee is offline   Reply With Quote
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
need your help about writing data to file john_tran Standard C, C++ 9 10-20-2004 04:43 AM
.htaccess -- Image Hotlinking Prevention DavH27 HTML / CSS 0 08-27-2004 03:43 AM
.htaccess -- Custom Error Pages v1.1 DavH27 HTML / CSS 0 08-26-2004 04:40 PM
Writing to a file. (PHP) Nasimov PHP 1 03-11-2004 05:19 AM
Binary I/O file reading (0x1a trouble) Danish Standard C, C++ 2 05-26-2003 10:02 AM


All times are GMT -8. The time now is 09:43 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle