• 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

How to Allow Write Access

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
I see the method setReadOnly() in File class.
The following is a quote from JAVA API for File class.
"After invoking this method the file or directory is guaranteed not to change until it is either deleted or marked to allow write access"
How can I mark a File object to allow write access?
Thanks
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Madan ,
The following solution is platform dependent
public class TestMath
public static void setWrite()
{
// java -Djava.security.policy=allpolicy.policy com.superiorpharm.TestMath
try
{
if( System.getSecurityManager() == null )
System.setSecurityManager(new SecurityManager());
SecurityManager s = System.getSecurityManager() ;
if( s != null )
s.checkExec("dir") ;
//Process p = Runtime.getRuntime().exec("C:\\Program Files\\Microsoft Office\\Office\\WINWORD.EXE") ;
System.out.println("Executing the process...");
// if it's windows
Process p = Runtime.getRuntime().exec("c:\\winnt\\system32\\attrib -r t.txt") ;
System.out.println("After Executing the process...");
InputStream ee = p.getInputStream() ;
int readInt = ee.read() ;
while( readInt != -1 )
{
System.out.print((char) readInt );
readInt = ee.read() ;
if( readInt == -1 )
break ;
}
ee = p.getErrorStream() ;
readInt = ee.read() ;
while( readInt != -1 )
{
System.out.print((char) readInt );
readInt = ee.read() ;
if( readInt == -1 )
break ;
}
System.exit(0);
}
catch(IOException e)
{
System.out.println("Unable to start the process " + e) ;
}
}
public static void main(String a[]) throws RxbException
{
TestMath.setWrite();
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic