肯定可以写,但需要加策略文件!我没太研究! 要想浏览服务器端的文件(TXT、HTML等)可以下面这样做! import java.applet.*; import java.awt.*; import java.net.*; public class BasicApplet extends Applet {
public void init() { // Called once by the browser when it starts the applet } public void start() { try { URL url = new URL(this.getDocumentBase(),"2.txt");
} catch (MalformedURLException e) { //textField1.setText(e.toString()); } // Called whenever the page containing this applet is made visible } public void stop() { // Called whenever the page containing this applet is not visible } public void destroy() { // Called once when the browser destroys this applet } public void paint(Graphics g) { // Called whenever this applet needs to repaint itself } }
URL urltmp = new URL(filepath);
当然filepath要形如http://*******/t.txt之类
后面的操作不用说了吧,咔咔,直接请求读取
我写了一些代码,但是出错,请帮忙看看:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.net.*;
//import java.util.*;public class writedata extends Applet
{
public void init()
{
try{
URL filedata=null;
//DataOutputStream dos=null;
filedata=new URL(getCodeBase()+"data.txt");
URLConnection con=filedata.openConnection();
PrintStream ps=new PrintStream(con.getOutputStream());
ps.println("aaa");
ps.close();
}catch(Exception e){System.out.println(e.getMessage());}
}
}
结果在html文件中浏览时,报错:protocol doesn't support output
有高手能指点一下吗?
要想浏览服务器端的文件(TXT、HTML等)可以下面这样做!
import java.applet.*;
import java.awt.*;
import java.net.*;
public class BasicApplet extends Applet {
public void init() {
// Called once by the browser when it starts the applet
}
public void start() {
try {
URL url = new URL(this.getDocumentBase(),"2.txt");
this.getAppletContext().showDocument(url,"_blank");
} catch (MalformedURLException e) {
//textField1.setText(e.toString());
} // Called whenever the page containing this applet is made visible
}
public void stop() {
// Called whenever the page containing this applet is not visible
}
public void destroy() {
// Called once when the browser destroys this applet
}
public void paint(Graphics g) {
// Called whenever this applet needs to repaint itself
}
}