Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:24:29+00:00 2026-05-28T04:24:29+00:00

I have a chat like desktop java swing app, where i keep getting String

  • 0

I have a chat like desktop java swing app, where i keep getting String type data. Eventually the String variable keeps growing larger and larger.

1) Is it wise idea to keep the large variable in memory and only when the logging is finished save this to disk.

2) If not, then should i continue saving everytime i get a new string (of length about 30-40).

How should i go about optimizing such a desgin?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:24:30+00:00Added an answer on May 28, 2026 at 4:24 am

    I would use a BufferedWriter, like PrintWriter. This will buffer the data for you and write every 8 KB (actually every 8192 characters). If you want to write more often you can use flush() or a smaller buffer.

    PrintWriter pw = new PrintWriter("my.log");
    
    // will actually write to the OS, 5 times. (1000 * 40 / 8192)
    for(int i = 0; i < 1000; i++) {
       pw.printf("%39d%n", i); // a 40 character number.
    }
    
    pw.flush();
    

    or you can use

    pw.println(lineOfText);
    

    BTW: If you want to know what a really huge file looks like 😉 This example writes an 8 TB file http://vanillajava.blogspot.com/2011/12/using-memory-mapped-file-for-huge.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which looks like: #chat :hi there And I'd like to
I have written an app that reads incoming chat(somewhat like an instant messenger), formats
I have the following app, that's like a chat, so I'm programmatically creating some
I have to implement gtalk like chat application using UDP in java. i have
I have seen lots of chat examples in Erlang but what about lists, like
I wish to have a java-chat on the iphone / ipad. With both, as
I have written a small chat app that uses mysql + php to facilitate
We have a facebook like chat, and we want to be able to play
i have a java chat server & client, that works fine. I made a
I have a chat CouchDB which stores records with following format. type:chat, email:p@g.com, friendEmail:m@g.com,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.