• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing to a file

 
priowan naratha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I do similar thing in writing to a file for unix system?
Thank you,
priowan

quote:
--------------------------------------------------------------------------------
Originally posted by Stephanie Grasson:
Hi Satya!
Here is a link that explains how to "Set up a Policy File to Grant the Required Permission". http://java.sun.com/docs/books/tutorial/security1.2/tour1/step2.html
I edited your code slightly (see below) and tried it with appletviewer and it worked. I set my permission as follows:
FilePermission = java.io.FilePermission
TargetName = c:\\temp\\iotest.log
Actions = write

code:
--------------------------------------------------------------------------------
// testing IO of Applets.// File: iotestApplet.javaimport java.io.*;import java.applet.*;import java.awt.*;import java.awt.event.*;public class iotestApplet extends Applet{ Label l; TextField tf; Button b; public void init() { l = new Label("Enter text here:"); add(l); tf = new TextField(40); add(tf); b = new Button("write"); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ try { PrintWriter out1 = new PrintWriter(new BufferedWriter ( new FileWriter("C:\\TEMP\\iotest.log"))); out1.println(tf.getText()); out1.close(); } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } }); add(b); }}
--------------------------------------------------------------------------------

code:
--------------------------------------------------------------------------------
<HTML><APPLET CODE = "iotestApplet.class" WIDTH = 640 HEIGHT = 480></APPLET></HTML>
--------------------------------------------------------------------------------
I have had limited success in granting permissions with Netscape. See this link for info: http://www.javaranch.com/ubb/Forum23/HTML/000234.html
Hope this helps.
Stephanie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic