• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Adding timestamp to txt file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone!

I'm doing a simple client-server programming assignment but I have difficulties with it.

One of the tasks is to create a txt file which stores the current timestamp and the message that was sent to the server by the client.

I can not figure out how to put these two informations into a separate text file. I've looked around for solutions but nothing seems to work.

Here's how a part of my code looks like:



The code above writes the recieved text and the current timestamp on the console, but I want it to write these to a txt file.

It does create a text file named "outputtext", but it's always empty..

Can you help me with this issue?

Thanks in advance!
 
Marshal
Posts: 72407
315
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use Date; use one of the newer datatypes described here in the Java™ Tutorials.
You can probably alter the formatting with String#format. The Formatter documentation has all the details in.
Where are you closing your reader and writer? If you don't close a writer, the text may remain in its buffer for ever and never appear at its intended destination. Don't call close(); read this Java™ Tutorials section, which tells you what you should do.
What is wrong with your program? We need the full details before we can help.
 
greg mic
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for the links and the information!!

I managed to pull it off, now both the message and the timestamp are in a separate text file. : )

I'm very grateful to you.
 
Campbell Ritchie
Marshal
Posts: 72407
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tha's a pleasure
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic