applet访问客户端
2006-02-21 17:02
369 查看
applet访问客户端
改变/jre1.5.0_06/lib/security/java.security。打开文件里面有policy.url.1和policy.url.2,我们可以创建自己的policy.url.3,我们需要一个.policy文件,此文件的作用指定对客户端的文件的操作权限。可以使用policytool工具自己创建.policy.
一个扩展自Applet的类,里边有个方法写文件,一个方法读文件。
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class MyFrame extends JFrame implements ActionListener{
JButton btRead = new JButton("Read");
JButton btWrite = new JButton("Write");
JTextArea txt1 = new JTextArea(null,8,35);
JScrollPane jspPanel = new JScrollPane(txt1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel jp = new JPanel();
public MyFrame(String title) {
super(title);
}
public void init()
{
Container con = this.getContentPane();
con.setLayout(new BorderLayout());
jp.add(btRead);
jp.add(btWrite);
con.add(jp,BorderLayout.NORTH);
con.add(jspPanel,BorderLayout.CENTER);
btRead.addActionListener(this);
btWrite.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getActionCommand().equals("Read"))
{
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("d://dbase//humor.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String s;
try {
while((s=in.readLine())!=null)
{
txt1.append(s+"/n");
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(arg0.getActionCommand().equals("Write"))
{
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter("d://dbase//humor.txt"));
} catch (IOException e) {
e.printStackTrace();
}
out.println("it is a humor");
out.close();
txt1.append("Write OK/n");
}
}
}
改变/jre1.5.0_06/lib/security/java.security。打开文件里面有policy.url.1和policy.url.2,我们可以创建自己的policy.url.3,我们需要一个.policy文件,此文件的作用指定对客户端的文件的操作权限。可以使用policytool工具自己创建.policy.
一个扩展自Applet的类,里边有个方法写文件,一个方法读文件。
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class MyFrame extends JFrame implements ActionListener{
JButton btRead = new JButton("Read");
JButton btWrite = new JButton("Write");
JTextArea txt1 = new JTextArea(null,8,35);
JScrollPane jspPanel = new JScrollPane(txt1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel jp = new JPanel();
public MyFrame(String title) {
super(title);
}
public void init()
{
Container con = this.getContentPane();
con.setLayout(new BorderLayout());
jp.add(btRead);
jp.add(btWrite);
con.add(jp,BorderLayout.NORTH);
con.add(jspPanel,BorderLayout.CENTER);
btRead.addActionListener(this);
btWrite.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getActionCommand().equals("Read"))
{
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("d://dbase//humor.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String s;
try {
while((s=in.readLine())!=null)
{
txt1.append(s+"/n");
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(arg0.getActionCommand().equals("Write"))
{
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter("d://dbase//humor.txt"));
} catch (IOException e) {
e.printStackTrace();
}
out.println("it is a humor");
out.close();
txt1.append("Write OK/n");
}
}
}
相关文章推荐
- ofbiz的webservice接口提供(3)-不规范的wsdl的客户端访问代码
- Exchange Server 2010 全新部署篇五:安装PEK1-CHS-01客户端访问及集线器传输角色
- IIS Web服务器已设置为允许匿名访问,但客户端仍然要求输入用户名和密码
- JMX客户端访问代码
- DCOM服务端及客户端指定用户访问的安全设置
- c# 访问Oracle11g的方法--无需客户端
- 客户端访问VSS数据库
- Windows 采用Socket方式实现服务器和客户端的数据访问
- Exchange Server 2003的客户端访问
- 开启MongoDB客户端访问控制
- 如何通过手机客户端Android、Iphone 等访问要求使用客户端证书SSL加密的https网站
- 在CentOS 5.8中安装Oracle客户端远程访问Oracle数据库服务器
- Spring提供RestTemplate用于访问Rest服务的客户端实践
- 深入Atlas系列:客户端网络访问基础结构(上) - WebRequest的工作流程与生命周期
- 深入Atlas系列:客户端网络访问基础结构示例(1) - 编写并使用自定义的WebRequestExecutor
- 编写Web Service客户端访问www.webxml.com.cn提供的服务
- Mac安装svn win系统svn客户端访问mac仓库
- Android开发进阶(七)-- Android客户端访问PHP服务器的详细过程
- VSS客户端不能访问问题“unable to open user login file\\服务器项目管理目录\data\logedin\用户名.log ”
- js 调用applet 访问本的文件