编写 JAVA 界面 获取文件地址

来源:百度知道 编辑:UC知道 时间:2024/05/28 09:40:15
现有Word转TXT代码如下
package bysj;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class Word2Txt {
public static void convert(String inputFile, String outputFile) {
boolean flag = false;

// 打开Word应用程序
ActiveXComponent app = new ActiveXComponent("Word.Application");
try {
// 设置word不可见
app.setProperty("Visible", new Variant(false));

// 打开word文件
Dispatch doc1 = app.getProperty("Documents").toDispatch();
Dispatch doc2 = Dispatch.invoke( doc1, "Open", Dispatch.Method,
new Object[] { inputFile, new Variant(false), new Variant(true) },
new int[1]).toDispatch();

// 作为txt格式保存到临时文件
Dispatch.invoke(doc2, "SaveAs", Di

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;

/**
*
* @author szmneo
*/

public class Word2Txt {
static JTextField tf1 = new JTextField(20);
static JTextField tf2 = new JTextField(20);
static String strDOC,strTXT;
public static void main(String[] args) {
JLabel l1 = new JLabel("要转换的WORD文档:");
JLabel l2 = new JLabel("要输出的TEXT文档:");
JButton b1 = new JButton("选择");
JButton b2 = new JButton("选择");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
p1.add(l1);
p1.add(tf1);
p1.add(b1);
p2.add(l2);
p2.