Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4267530
Votes 4
Synopsis File.setHidden() to create a hidden file
Category java:classes_io
Reported Against 1.2
Release Fixed
State 11-Closed, duplicate of 4313887, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 01-SEP-1999
Description


There is no way to create a hidden file on windows platforms.

I suggest a setHidden(java.io.File) method which sets the hidden
bit in the windows file attribute, or prefixes the file name 
with a period under UNIX. I dont know the methods used on other platforms.

(see also bug # 4131223 --  xxxxx@xxxxx  , 8/31/99)
(Review ID: 94650) 
======================================================================
Posted Date : 2005-08-25 20:54:48.0
Work Around
N/A
Evaluation
A new JSR to cover upcoming filesystem work will be submitted soon. We will
add this request to the list of issues to be considered in the new JSR.
  xxxxx@xxxxx   2002-03-28
There are no plans to provide a method exactly as requested but the new file system API defined by JSR-203 does allow the DOS hidden attribute to be set.
Posted Date : 2009-02-16 15:50:35.0
Comments
  
  Include a link with my name & email   

Submitted On 17-JAN-2000
hmorgenstern
this is an important and obvious feature to have access to. There should be
such low level access to the file attributes including access to setting all
other file attributes not currently available


Submitted On 26-JUN-2001
sk33sk33
I just started programming with java - and I am shocked 
about this matter!!!! I tried(!?) to program a FTP Client 
(which should set the archive flag after upload).

no help at all?!?


Submitted On 17-MAY-2006
cowwoc
Any idea why this method wasn't added alongside Mustang's setReadable(), setWriteable() and setExecutable()?


Submitted On 20-JAN-2008
amclay
I would like to see a filesystem class that would read data from the filesystem.  Then we could implement other code much more efficiently and easily.


Submitted On 21-JAN-2008
PasiM
Definitely yes! This should have been in File class since Java 1.0

Even though I wouldn't implement it same way than mentioned in this bug/rfe description. Instead, File class should have non-static method setHidden(boolean) that would work exactly like setReadable(boolean), setWritable(boolean) and setExecutable(boolean) which already exists. Method setHidden(boolean) would return false in case OS doesn't support setting files hidden or it can not be done to current file.

This already happens with setReadable(false) and setExecutable(false) methods in Windows systems. Windows doesn't support 'readable' and 'executable' flags like Unix, therefore it does nothing to file and returns false. Same way setHidden(boolean) would return false in Unix.

Ok, now someone is saying that Unix does support hidden files. Yes, but changing file to hidden would change file name, causing several problems. Ok, now someone is saying that setHidden(boolean) returning false in Unix is not correct, because hidden files are supported after all. Fine, let's change method name to setHiddenFlag(boolean) or setHiddenAttribute(boolean) then. This way method name is already telling that it's exactly _the 'hidden' flag of the file_ we want to change, if it's just possible.

I really do not understand why this kind of basic file function still isn't in Java :-(  If there's just some simple reason why not, please let me know too...


Submitted On 13-FEB-2008
PolianaINATEL
Hi.. Itīs so simple .. 

To create a hidden file on windows platforms using java you need to use runtime..

Example:

File arquivo = new File("Example.txt");
arquivo.createNewFile();
String comando = "C:\\WINDOWS\\System32\\ATTRIB.EXE +H Example.txt";

Runtime.getRuntime().exec(comando );



Submitted On 19-FEB-2008
PasiM
PolianaINATEL: True and I'm actually used that in one program which I was sure that will be used only in windows.

However, that would pretty much lose idea of Java programs being platform independent. Even I used windows as example, there might be other platforms too which support hidden flag and it would be nice if programs would work on those too.

There's also risk that running command "attrib" could in some systems do something else than set file attributes. Unlikely, but possible. So I do not see using Runtime.exec() very good general and/or long term solution to this.

Thanks for commenting though :-)



PLEASE NOTE: JDK6 is formerly known as Project Mustang