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("file.separator"<br>
<br>
try<br>
{<br>
if(SecurityContext.isCapableOf("SuperUser")<br>
{<br>
PrivilegeManager.enablePrivilege("SuperUser" <br>
}<br>
<br>
<br>
<br>
String userdir = System.getProperty("user.dir"<br>
g.drawString("Successfully read user dir", 10, 10);<br>
<br>
String fileName = userdir + slash + "lytest";<br>
<br>
DataOutputStream dos;<br>
dos = new DataOutputStream(new FileOutputStream(fileName));<br>
dos.writeChars("Written by a LY trusted applet"<br>
g.drawString("Successfully write", 10, 20);<br>
<br>
dos.close();<br>
g.drawString("Successfully close", 10, 30);<br>
<br>
<br>
Process p = Runtime.getRuntime().exec("copy " + userdir + slash + "lytest" + " " + "LPT1"<br>
//Runtime rt = java.lang.Runtime.getRuntime();<br>
//rt.exec("copy " + fileName + " " + "LPT1"<br>
<br>
g.drawString("Close file...hahah", 10, 40);<br>
}<br>
catch (Exception e)<br>
{<br>
g.drawString("Got exception...leh" , 10, 50);<br>
g.drawString(e.toString() , 10, 70);<br>
}<br>
<br>
}<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("file.separator"<br>
<br>
try<br>
{<br>
if(SecurityContext.isCapableOf("SuperUser")<br>
{<br>
PrivilegeManager.enablePrivilege("SuperUser" <br>
}<br>
<br>
<br>
<br>
String userdir = System.getProperty("user.dir"<br>
g.drawString("Successfully read user dir", 10, 10);<br>
<br>
String fileName = userdir + slash + "lytest";<br>
<br>
DataOutputStream dos;<br>
dos = new DataOutputStream(new FileOutputStream(fileName));<br>
dos.writeChars("Written by a LY trusted applet"<br>
g.drawString("Successfully write", 10, 20);<br>
<br>
dos.close();<br>
g.drawString("Successfully close", 10, 30);<br>
<br>
<br>
Process p = Runtime.getRuntime().exec("copy " + userdir + slash + "lytest" + " " + "LPT1"<br>
//Runtime rt = java.lang.Runtime.getRuntime();<br>
//rt.exec("copy " + fileName + " " + "LPT1"<br>
<br>
g.drawString("Close file...hahah", 10, 40);<br>
}<br>
catch (Exception e)<br>
{<br>
g.drawString("Got exception...leh" , 10, 50);<br>
g.drawString(e.toString() , 10, 70);<br>
}<br>
<br>
}<br>
}