1 Replies - 341 Views - Last Post: 24 January 2013 - 09:51 PM Rate Topic: -----

#1 GodSosukeAizen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-January 13

Writing to a file new line

Posted 24 January 2013 - 09:09 PM

Whenever I write to my file after the registration form and it is successful it overwrites existing data in the text document rather than adding a new line, I tried to get it working by using environment.newline but it didn't work.

' Wtites data to file.
            FileWriter.WriteLine(Userdata)
            FileWriter.Write(Environment.NewLine)
http://www.dreamincode.net/forums/index.php?app=forums&module=post&section=post&do=new_post&f=67#
            FileWriter.Close()



Sorry for the link to somewhere I don't know how that happened.

Is This A Good Question/Topic? 0
  • +

Replies To: Writing to a file new line

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,176
  • Joined: 18-April 07

Re: Writing to a file new line

Posted 24 January 2013 - 09:51 PM

How are you opening the FileWriter? If you are not opening the writer in append mode, it will erase the file prior to writing. Check out the FileMode enumeration.

I am hoping you are not writing Java here in the VB.NET forum. If you are writing Java then it would be again how you open the writer. The filewriter class can use as second parameter to the constructor that is either true/false for whether or not it should be in append mode.

In other words...

// True here is saying make it append mode
FileWriter writer = new FileWriter("mytextfile.txt",true);



P.S. Again if you are in Java it is advisable to be using the BufferedWriter class for better performance.

:)

This post has been edited by Martyr2: 24 January 2013 - 09:53 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1