如何打开本地html文件并显示结果(注意不是html的原文件)在线等!速结帖!! 如题,最好有例子或源码,出结果就结帖!谢谢各位!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ??????打开客户端的文件?不行的。或着用Applet+授权服务器端的就是普通文件操作了 我做的是一个浏览器想打开本地的文件因为我不知道怎么打开其他服务器的文件,我不会配这是一个例子import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;class Win extends JFrame implements ActionListener,Runnable{ JButton button; URL url; JTextField text; JEditorPane editPane; byte b[]=new byte[118]; Thread thread; public Win() { text=new JTextField(20); editPane=new JEditorPane(); editPane.setEditable(false); button=new JButton("确定"); button.addActionListener(this); thread=new Thread(this); JPanel p=new JPanel(); p.add(new JLabel("输入网址:")); p.add(text); p.add(button); Container con=getContentPane(); con.add(new JScrollPane(editPane),BorderLayout.CENTER); con.add(p,BorderLayout.NORTH); setBounds(60,60,360,300); setVisible(true); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e) { if(!(thread.isAlive())) thread=new Thread(this); try{ thread.start(); } catch(Exception ee) { text.setText("我正在读取"+url); } } public void run() { try { int n=-1; editPane.setText(null); url=new URL(text.getText().trim()); editPane.setPage(url); } catch(MalformedURLException e1) { text.setText(""+e1); return; } catch(IOException e1) { text.setText(""+e1); return; } }}public class Example{ public static void main(String args[]) { new Win(); }} 完了,又废了50分我自己会了,只要把File类型的变量file变成URL型的就可以了,用的方法是file.toURL();然后再用JEditPane显示就可以了。现在全当散分了,我高兴了就结贴。 JEditPane直接指定url就可以显示了如果想用浏览器访问只要Runtime.getRuntime("iExplorer C:\\xxx.htm"); 五子棋,但是菜单不知道怎么实现??帮忙啊 怎样遍历internet某个网站上的某个url路径下的全部文件 我被折磨死了 怎么在这里发图片? 读取xml数据写入数据库的效率问题 三峡大学 在校大学生 Vector问题 关于jbuilder生成jar问题,100分奉送,急!!! 调出另一个窗体怎么做? public void paint(Graphics g)的问题??谢谢!! ::::: 发现一个功能强大的Java剖析工具,要的进来看 ::::: 请教大吓们:String 与 StringBuffer 有什么区别??!! -- 急切中...
打开客户端的文件?不行的。或着用Applet+授权
服务器端的就是普通文件操作了
想打开本地的文件
因为我不知道怎么打开其他服务器的文件,我不会配
这是一个例子
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
class Win extends JFrame
implements ActionListener,Runnable
{
JButton button;
URL url;
JTextField text;
JEditorPane editPane;
byte b[]=new byte[118];
Thread thread;
public Win()
{
text=new JTextField(20);
editPane=new JEditorPane();
editPane.setEditable(false);
button=new JButton("确定");
button.addActionListener(this);
thread=new Thread(this);
JPanel p=new JPanel();
p.add(new JLabel("输入网址:"));
p.add(text);
p.add(button);
Container con=getContentPane();
con.add(new JScrollPane(editPane),BorderLayout.CENTER);
con.add(p,BorderLayout.NORTH);
setBounds(60,60,360,300);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
thread=new Thread(this);
try{
thread.start();
}
catch(Exception ee)
{
text.setText("我正在读取"+url);
}
}
public void run()
{
try {
int n=-1;
editPane.setText(null);
url=new URL(text.getText().trim());
editPane.setPage(url);
}
catch(MalformedURLException e1)
{
text.setText(""+e1);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return;
}
}
}
public class Example
{
public static void main(String args[])
{
new Win();
}
}
我自己会了,只要把File类型的变量file变成URL型的就可以了,用的方法是file.toURL();
然后再用JEditPane显示就可以了。
现在全当散分了,我高兴了就结贴。
Runtime.getRuntime("iExplorer C:\\xxx.htm");