Read a file without changing its access time ?

1) Is it possible to read a file using a fileInputStream but without updating its Last Access Time ?

2) Or maybe someway to first get the Last Access Time, then read the file and then change the access time of that file back to what it was before the read ?

3) Is it possible to do this using any other programming language that you might know of (In the windows environment)

4) Does anyone know how to read a file by disabling access time updates on windows ?

Thanks in advance. :))

[514 byte] By [the_learnera] at [2007-11-27 10:26:52]
# 1

And you want to do this because...?

jverda at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 2

its just that for some users of my program it is important to maintain the access times of the files.

the_learnera at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 3

what exactly is your program ?

Aknibbsa at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 4

How about:

File file=new File("");

long x1= file.lastModified();

((( read the file))))

file.setLastModified(x1);

George123a at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 5

> How about:

>

> File file=new File("");

> long x1= file.lastModified();

>

> ((( read the file))))

>

> file.setLastModified(x1);

last modified != last accessed.

Aknibbsa at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 6

> its just that for some users of my program it is

> important to maintain the access times of the files.

But that's exactly what's happening. The access times of the files are being maintained correctly. The question is why do you not want tha to happen?

ejpa at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 7

I guess there is no way in java to get and set access time of a file.

In that case, I thought I would invoke a perl script from within my java program to get the job done. However, for that purpose the users will need to have perl installed on their machine, am I right ?

If so, then which other programming or scripting language can I use (on windows) so that users do not need to install anything else ?

the_learnera at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 8

> I guess there is no way in java to get and set access

> time of a file.

>

> In that case, I thought I would invoke a perl script

> from within my java program to get the job done.

> However, for that purpose the users will need to have

> perl installed on their machine, am I right ?

>

> If so, then which other programming or scripting

> language can I use (on windows) so that users do not

> need to install anything else ?

I do not believe there is an exposed API (at least not in Windows) which allows one to set the last accessed time of a file. Obviously at least the OS can reset it (as it is doing when you open the file thru any means), but I doubt this is exposed for applications (not even in C, C++ or possibly even lower-level Assembler) to monkey with.

Nor should it be monkeyed with. You are apparently designing an ill-designed application which should not be using last-accessed time as a control in the first place.

warnerjaa at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 9

Well there is a perl function utime(atime,mtime) which allows you to set the access and modification time for files.

C on unix has utime too..

C on windows has setFileTime()

setFileTime:

Sets the date and time that the specified file or directory was created, last accessed, or last modified.

the_learnera at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 10

You still haven't told us why you want to do this.

If you want to update the last-accessed time of a file to 'now', just open it and close it. If you want to update the last-write time of a file to 'now', open it, read the first byte, write it back, and close it (that's what 'touch' does, or did).

If you want to set the last-accessed time backwards to some previous time, I would want to know why.

ejpa at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 11

> You still haven't told us why you want to do this.

>

Probably trying to write a spyware program.

floundera at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...
# 12

one reason to want to preserve a file accessed date is for legal discovery purposes. if your program opens files for the purpose of indexing their content, and through that indexing you determine that the file needs to be preserved exactly as it is (was), you will need to reset the 'last access' time to preserve that file. this is, most likely, not what the OP had in mind, but i just wanted to point out that there are valid reasons for wanting to do this.

derekoneila at 2007-7-28 17:42:00 > top of Java-index,Java Essentials,Java Programming...