Re: 关于APPLET的IO问题# Java - 爪哇娇娃
l*d
1 楼
我试了一下,没问题呀。就是IE5的VM好像不合spec,getDocumentBase()连文件名都返回了。所以做了点改动。这是我试验的Code,你参考一下。
MyApplet.java:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
add(textArea1);
textArea1.setBounds(20,20,600,440);
textArea1.setText(getDocumentBase()+"\n");
try {
URL url = new URL(getDocumentBase(), "text.txt");
textArea1.setText(url.toString()+"\n");
URLConnection conn = url.openConnection()
MyApplet.java:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
add(textArea1);
textArea1.setBounds(20,20,600,440);
textArea1.setText(getDocumentBase()+"\n");
try {
URL url = new URL(getDocumentBase(), "text.txt");
textArea1.setText(url.toString()+"\n");
URLConnection conn = url.openConnection()