Quantcast

Bug in File.getLastModified()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Bug in File.getLastModified()

Ricardo Almeida
Hi,

I could not raise a bug in https://bugs.openjdk.java.net/ so I hope it
is ok to say it here, hoping someone can take a look at it...

File.getLastModified() always returns with second precision, losing
the miliseconds (i.e. a number ending in 000). I tried using
Files.getLastModifiedTime and it seems to work correctly as the output
of the following test app shows:

Test f.lastModified [1490606336000]: false
Test Files.getLastModifiedTime [1490606336718]: true

The code:

package com.espatial.test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class FileTest {
    private static final long LM = 1490606336718L;

    public static void main(String[] args) throws IOException {
        File f = new File("test.txt");
        f.createNewFile();

        f.setLastModified(LM);

        System.out.printf("Test f.lastModified [%s]: %b\n",
f.lastModified(), f.lastModified() == LM);
        System.out.printf("Test Files.getLastModifiedTime [%s]: %b\n",
Files.getLastModifiedTime(f.toPath()).toMillis(),
(Files.getLastModifiedTime(f.toPath()).toMillis() == LM));

        f.delete();
    }
}

Thanks you,
Regards,
Ricardo Almeida
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Bug in File.getLastModified()

dalibor topic-2
On 29.03.2017 16:40, Ricardo Almeida wrote:
> Hi,
>
> I could not raise a bug in https://bugs.openjdk.java.net/

Hi,

please use bugs.java.com to file issues if you're not an OpenJDK developer.

cheers,
dalibor topic

--
<http://www.oracle.com> Dalibor Topic | Principal Product Manager
Phone: +494089091214 <tel:+494089091214> | Mobile: +491737185961
<tel:+491737185961>

ORACLE Deutschland B.V. & Co. KG | Kühnehöfe 5 | 22761 Hamburg

ORACLE Deutschland B.V. & Co. KG
Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
Geschäftsführer: Alexander van der Ven, Jan Schultheiss, Val Maher

<http://www.oracle.com/commitment> Oracle is committed to developing
practices and products that help protect the environment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Bug in File.getLastModified()

David Holmes
In reply to this post by Ricardo Almeida
Hi Ricardo,

This isn't a build issue. Redirecting to core-libs-dev. Please don't
reply to build-dev.

Thanks,
David

On 30/03/2017 12:40 AM, Ricardo Almeida wrote:

> Hi,
>
> I could not raise a bug in https://bugs.openjdk.java.net/ so I hope it
> is ok to say it here, hoping someone can take a look at it...
>
> File.getLastModified() always returns with second precision, losing
> the miliseconds (i.e. a number ending in 000). I tried using
> Files.getLastModifiedTime and it seems to work correctly as the output
> of the following test app shows:
>
> Test f.lastModified [1490606336000]: false
> Test Files.getLastModifiedTime [1490606336718]: true
>
> The code:
>
> package com.espatial.test;
>
> import java.io.File;
> import java.io.IOException;
> import java.nio.file.Files;
>
> public class FileTest {
>     private static final long LM = 1490606336718L;
>
>     public static void main(String[] args) throws IOException {
>         File f = new File("test.txt");
>         f.createNewFile();
>
>         f.setLastModified(LM);
>
>         System.out.printf("Test f.lastModified [%s]: %b\n",
> f.lastModified(), f.lastModified() == LM);
>         System.out.printf("Test Files.getLastModifiedTime [%s]: %b\n",
> Files.getLastModifiedTime(f.toPath()).toMillis(),
> (Files.getLastModifiedTime(f.toPath()).toMillis() == LM));
>
>         f.delete();
>     }
> }
>
> Thanks you,
> Regards,
> Ricardo Almeida
>
Loading...