Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this code (Applet) ?

Status
Not open for further replies.

slok

Programmer
Jul 2, 1999
108
SG
I wanted to create an applet for Netscape that <br>
creates a file on the user machine and then send the<br>
file to the LPT1 (printer).<br>
<br>
However, there is some problems about access rites ?<br>
any ideas ?<br>
<br>
thanks<br>
<br>
====<br>
import java.awt.*;<br>
import java.awt.event.*;<br>
import java.applet.*;<br>
import java.net.*;<br>
import java.io.*;<br>
import java.lang.Runtime;<br>
import netscape.security.PrivilegeManager;<br>
<br>
public class WriteFile extends Applet {<br>
<br>
public void paint (Graphics g)<br>
{<br>
String slash = System.getProperty(&quot;file.separator&quot;);<br>
<br>
try<br>
{<br>
if(SecurityContext.isCapableOf(&quot;SuperUser&quot;))<br>
{<br>
PrivilegeManager.enablePrivilege(&quot;SuperUser&quot;); <br>
}<br>
<br>
<br>
<br>
String userdir = System.getProperty(&quot;user.dir&quot;);<br>
g.drawString(&quot;Successfully read user dir&quot;, 10, 10);<br>
<br>
String fileName = userdir + slash + &quot;lytest&quot;;<br>
<br>
DataOutputStream dos;<br>
dos = new DataOutputStream(new FileOutputStream(fileName));<br>
dos.writeChars(&quot;Written by a LY trusted applet&quot;);<br>
g.drawString(&quot;Successfully write&quot;, 10, 20);<br>
<br>
dos.close();<br>
g.drawString(&quot;Successfully close&quot;, 10, 30);<br>
<br>
<br>
Process p = Runtime.getRuntime().exec(&quot;copy &quot; + userdir + slash + &quot;lytest&quot; + &quot; &quot; + &quot;LPT1&quot;);<br>
//Runtime rt = java.lang.Runtime.getRuntime();<br>
//rt.exec(&quot;copy &quot; + fileName + &quot; &quot; + &quot;LPT1&quot;);<br>
<br>
g.drawString(&quot;Close file...hahah&quot;, 10, 40);<br>
}<br>
catch (Exception e)<br>
{<br>
g.drawString(&quot;Got exception...leh&quot; , 10, 50);<br>
g.drawString(e.toString() , 10, 70);<br>
}<br>
<br>
}<br>
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top