如何将HTML文件显示为网页? [英] How can I display an HTML file as a web page?

查看:241
本文介绍了如何将HTML文件显示为网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码读取一个HTML文件,我想在新框架中显示它作为网页。
但我不知道 - 我该怎么做?



这是我的代码:

  public class EditorPaneLoad extends JFrame {
$ b $ public EditorPaneLoad()throws Exception {

FileReader reader = new FileReader(a.html );
JEditorPane editor = new JEditorPane();
JTextPane editor = new JTextPane();
editor.setContentType(text / html);
editor.setEditable(false);
editor.read(reader,null);
//System.out.println(editor.getText());
//System.out.println(\"\\\
------------\\\
);
Document doc = editor.getDocument();
// System.out.println(doc.getText(0,doc.getLength()));
JScrollPane scrollPane = new JScrollPane(editor);
scrollPane.setPreferredSize(new Dimension(300,200));
getContentPane()。add(scrollPane);
}

public static void main(String [] args)
throws Exception
{
EditorPaneLoad frame = new EditorPaneLoad();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);


$ / code $ / pre

解决方案

<$ p $ (默认浏览器中打开a.html)。

请参阅 Desktop.open(File) 了解详情。


My code reads an HTML file and I want to show it in new frame as a web page. But I don't know - how can I do this?

This is my code:

public class EditorPaneLoad extends JFrame{ 

public EditorPaneLoad() throws Exception{

    FileReader reader = new FileReader("a.html");
    JEditorPane editor = new JEditorPane();
    JTextPane editor = new JTextPane();
    editor.setContentType( "text/html" );
    editor.setEditable( false );
    editor.read(reader, null);
    //System.out.println(editor.getText());
    //System.out.println("\n------------\n");
    Document doc = editor.getDocument();
    // System.out.println(doc.getText(0, doc.getLength()));
    JScrollPane scrollPane = new JScrollPane( editor );
    scrollPane.setPreferredSize( new Dimension(300, 200) );
    getContentPane().add( scrollPane );
}

public static void main(String[] args)
    throws Exception
{
    EditorPaneLoad frame = new EditorPaneLoad();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.pack();
    frame.setLocationRelativeTo( null );
    frame.setVisible(true);
}
}

解决方案

// opens "a.html" in the default browser..
Desktop.getDesktop().open(new File("a.html"));

See Desktop.open(File) for details.

这篇关于如何将HTML文件显示为网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆