• 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

file.lastmodified () problem

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Every one.

I wrote some code to get a list of files in a directory and print their last modified time with the filename into an output file.

This is the code


When i ran this code on a Windows machine i got the output without any problems but when i ran it on an AIX 5.3 Box with Ibm Jdk 1.4.2 SR3 it gave the following error

FileModify.java:27: incompatible types
found : long
required: java.lang.Long
Long lastmod = files[i].lastModified();
^
1 error



Can you tell me what am i doing wrong here?

Thanks
Kaz
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the java version on your windows box 1.5 or higher by chance?

Autoboxing was introduced in 1.5, so you will need to handle it explicitly on older java versions. Or if possible, upgrade on the unix box.
[ March 08, 2007: Message edited by: David McCombs ]
 
kaz juback
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David
Yes i have JDK 5 on my Windows system.
Can you tell me what you mean by explicitly handle it?
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What allows you to do this: Long lastmod = files[i].lastModified(); in java 1.5+ is called autoboxing. It automatically handles the conversion from the primitive long that lastModified() returns to an object of type Long.

This is not available in versions of Java prior to 1.5, which is why you are getting complaints on the older version of Java.

To handle it, you need to explicitly handle it, here is one way:

Long lastmod = new Long(files[i].lastModified());

or you could change lastmod to type long.
 
kaz juback
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot David.
That worked just fine.

Its great to see people helping out others :-)

Kaz
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.

We are all here to learn and help when we can.

For more information on Autoboxing
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic