• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Allow Write Access

 
Madan, Gopal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • 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
 
manoj bagul
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!