java中建立打开对话框
伤逝_离愁 2012-06-27 06:23:21 // 1、打开文件处理事件
openFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileDialog openFileDialog = new FileDialog(frame, "打开",
FileDialog.LOAD);
openFileDialog.setVisible(true);
textArea.setVisible(true);
// 得到文件名
String openedFileName = openFileDialog.getFile();
String openedFileDirectory = openFileDialog.getDirectory();
String openedFilePath = openedFileDirectory + openedFileName;
if (openedFileName.equals("") || openedFileName == null) {
frame.setTitle("无标题 - 记事本");
} else {
frame.setTitle(openedFileName + " - 记事本");
}
try {
writerBuffertoJTextArea(openedFilePath, textArea);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
其中怎样添加打开任意类型的文件而不会产生乱码