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 7742191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:13:14+00:00 2026-06-01T09:13:14+00:00

ANSWER: You cannot write an int directly to a file. Convert it to a

  • 0

ANSWER:
You cannot write an int directly to a file. Convert it to a string first.


Original Question:

I know that this may sound like a nooby question, but I have nowhere else to turn.

I’m trying to make Java write the Epoch (timestamp) to a .session file (don’t ask). It doesn’t seem to do anything. Here is what I have:

    gamesession = new File(SESSION_LOCATION);   // Sets the .session file

    if(gamesession.exists()){
        gamesession.delete();
        gamesession.createNewFile();

        FileWriter stream = new FileWriter(SESSION_LOCATION);
        BufferedWriter out = new BufferedWriter(stream);

        out.write(GetTimestamp());
        out.flush();
    }                       // These blocks write the Epoch to the .session file for later time
    else{
        gamesession.createNewFile();

        FileWriter stream = new FileWriter(SESSION_LOCATION);
        BufferedWriter out = new BufferedWriter(stream);

        out.write(GetTimestamp());
        out.flush();
    }

Yes, the method is DECLARED to throw a IOException (none occurs @ runtime). The problem is that, the .session file I’m writing to always turns up empty. Am I flushing wrong? Please help me shine some light on this. Thanks for your time.

FYI: The Epoch is calculated correctly, as I did System.out.println(GetTimestamp()).

GetTimestamp() is MY method. It is static.

  • 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-06-01T09:13:15+00:00Added an answer on June 1, 2026 at 9:13 am

    You need to make sure to call the out.close() method as well. I’ve noticed that sometimes when dealing with Files if you don’t close them the contents don’t show up.

    Also what type does GetTimestamp() return? According to BufferedWriter API the write method takes an int that is supposed to be character. I doubt your timestamp is a single char.

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

Sidebar

Related Questions

I have a relatively simple question that I cannot seem to find the answer
I know, I know... Eric Lippert's answer to this kind of question is usually
WCF gurus, you probably already know the answer I cannot find ... let's say
Simple question but cannot find answer anywhere. When using a MS Chart Control of
i cannot seem to find the answer to this. i uploaded code to pastebin
I cannot seem to find the answer to this I am looking for a
I have looked everywhere for this and just cannot find the answer. I have
I need to write an algorithm(I cannot use any 3rd party library, because this
I used an answer to the SO question iterate over tuple to write a
I cannot write Javascript code yet, and I'm trying to edit some code that

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.