Forums Register Login

file.lastmodified () problem

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Hi David
Yes i have JDK 5 on my Windows system.
Can you tell me what you mean by explicitly handle it?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks a lot David.
That worked just fine.

Its great to see people helping out others :-)

Kaz
+Pie Number of slices to send: Send
You're welcome.

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

For more information on Autoboxing
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3882 times.
Similar Threads
[newbie] String.replace()/replaceAll() removed spaces
FileName to write to a .txt File
Checking for a file name with a date/timestamp mask
Copy file
Help with something Simple
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:21:55.