• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Long variables and File

 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we write long variables as date to a file?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, ofcourse.

If you want more detailed information on how to do that, you'll have to explain in much more detail what exactly the problem is and what exactly you want the file to contain.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a date in a file. I want to write it because I need to see the last time the program has been run.
I am working on Net beans in Ubuntu. If I convert it to an integer and write it to a file, some Chinese letters are displayed in the file.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't convert it to an integer. It isn't an integer. Calling date.toString() converts it into a human readable String. If you need a different format, look at the SimpleDateFormat class.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Partheban Udayakumar wrote:I am trying to write a date in a file. I want to write it because I need to see the last time the program has been run.
I am working on Net beans in Ubuntu. If I convert it to an integer and write it to a file, some Chinese letters are displayed in the file.



You have to remember that OS commands that print the file (such as the "type" or "cat" commands) and text editors (which are used to examine such files) are designed for text files. When you write binary data such as integers and long, it is no longer a text file. It is now a binary file. The integer is saved correctly, and you can read it back too. However, it is not a text file, and hence, can not be examined by the tools designed for text files.

If you want to write integers or longs, so that it can be read by a text file based tool, you will need to convert the value into a string first. Try using the toString() method of the Integer class. Or the DecimalFormat class. Or since it is a date, the SimpleDateFormat Class.

Henry

 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry,

Thanks for the advice. I got the desired result.

reply
    Bookmark Topic Watch Topic
  • New Topic