Results 1 to 7 of 7

Thread: BufferedWriter

  1. #1
    Karthika is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default BufferedWriter

    Hi,
    I want to write a date to a file using BufferedWriter. But the BufferedWriter's write function does not support Date data type. I cannot convert that to string also as I get an error for that. I like to know how to solve this problem.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Karthika View Post
    Hi,
    I want to write a date to a file using BufferedWriter. But the BufferedWriter's write function does not support Date data type. I cannot convert that to string also as I get an error for that. I like to know how to solve this problem.
    What is the exception/compilation problem? Have you tried to write date.toString()?

    kind regards,

    Jos

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Or, if you want to control the format of the output, a SimpleDateFormat?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    Or, if you want to control the format of the output, a SimpleDateFormat?
    If I were the OP I'd wrap the BufferedWriter in a PrintWriter, print dates, times and other formatted stuff and be done with it.

    kind regards,

    Jos

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Depends if they want to learn the format codes or not.
    Not that they're particularly difficult.
    But if it's just a date an SDF might be simpler?
    Who knows, without a spec.

  6. #6
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Easiest solution - do a

    long millis = date.getTime()

    and write millis to the data file. The when reading it back, do

    Date date = new Date(millis);

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

Similar Threads

  1. Null Pointer Exception with BufferedWriter
    By Sasquatch192 in forum New To Java
    Replies: 3
    Last Post: 10-26-2009, 07:32 PM
  2. Replies: 0
    Last Post: 06-26-2008, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •