如何在java中使用path检索图像或文本文件?
我想从这个文件中得到的确切信息是,首先我在flash的基础上进行了数据集收集。在dat中,我考虑了swf和flv文件。使用Java脚本和eclipse平台,我们需要在Java上显示网页,我显示了那个网页。现在在同一个程序中,我需要一个代码从桌面获取文件路径,并将其显示在类似eclipse框架的网页上 显示,我需要获取一个类似flv和swf的文件。但现在至少我必须显示一些txt文件和图像。请帮帮我如何在java中使用path检索图像或文本文件?,java,eclipse,swing,Java,Eclipse,Swing,我想从这个文件中得到的确切信息是,首先我在flash的基础上进行了数据集收集。在dat中,我考虑了swf和flv文件。使用Java脚本和eclipse平台,我们需要在Java上显示网页,我显示了那个网页。现在在同一个程序中,我需要一个代码从桌面获取文件路径,并将其显示在类似eclipse框架的网页上 显示,我需要获取一个类似flv和swf的文件。但现在至少我必须显示一些txt文件和图像。请帮帮我 package browser; import javax.swing.*; import jav
package browser;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class modifiedcode extends JFrame {
public JPanel address_panel, window_panel;
public JLabel address_label;
public JTextField address_tf;
public JEditorPane window_pane, tree_pane, attr_pane;
public JScrollPane window_scroll, tree_scroll, attr_scroll;
TextArea t1, t2;
public JButton address_b;
private Go go = new Go();
public modifiedcode() throws IOException {
// Define address bar
address_label = new JLabel(" address: ", SwingConstants.CENTER);
address_tf = new JTextField("http://www.yahoo.com", 25);
address_tf.setBounds(80, 10, 150, 30);
address_label.setBounds(10, 10, 70, 30);
address_tf.addActionListener(go);
address_b = new JButton("Go");
address_b.setBounds(240, 10, 50, 30);
address_b.addActionListener(go);
address_panel = new JPanel();
address_panel.setLayout(null);
window_pane = new JEditorPane("http://www.yahoo.com") {
public boolean getScrollableTracksViewportWidth() {
return true;
}
};
JPanel noWrapPanel = new JPanel(new BorderLayout());
noWrapPanel.add(window_pane);
window_pane.setContentType("text/html");
window_pane.setEditable(false);
t1 = new TextArea();
t1.setBounds(650, 380, 300, 250);
t2 = new TextArea();
t2.setBounds(650, 50, 300, 280);
JLabel l = new JLabel("Tree");
l.setBounds(650, 30, 300, 10);
JScrollPane window_scroll = new JScrollPane();
window_scroll
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
window_scroll
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
window_scroll.setViewportView(noWrapPanel);
window_scroll.setBounds(10, 50, 600, 600);
window_scroll.setPreferredSize(new Dimension(600, 600));
window_pane.setBounds(10, 50, 600, 600);
JFrame f = new JFrame("Web browser");
JPanel pane = new JPanel();
pane.setLayout(null);
// pane.add(window_pane);
pane.add(window_scroll);
pane.add(t2);
pane.add(address_label);
pane.setVisible(true);
pane.add(address_tf);
pane.add(address_b);
pane.add(l);
pane.add(t1);
f.setContentPane(pane);
f.setSize(1000, 700);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class Go implements ActionListener {
public void actionPerformed(ActionEvent ae) {
try {
window_pane.setPage(address_tf.getText());
} catch (MalformedURLException e) { // new URL() failed
window_pane.setText("MalformedURLException: " + e);
} catch (IOException e) { // openConnection() failed
window_pane.setText("IOException: " + e);
}
}
}
public static void main(String args[]) throws IOException {
modifiedcode wb = new modifiedcode();
}
}
要从路径获取文件,可以使用JFrame.class.getResourceAsFile()。这将在类路径上找到资源。欢迎使用堆栈溢出。请阅读。提问时,在发帖前花些时间阅读你的问题,注意拼写和语法。在写糟糕的问题时,你的问题很可能被忽略。