//費了我一會功夫給你編了個讀取文件的程序,你看看是不是你想要的,我這有個java學習討論群(77077753),你可以加入,有什麼問題可以在群里討論!!
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class wenjian
extends Frame
implements ActionListener {
FileDialog open = new FileDialog(this, "打開文件",
FileDialog.LOAD);
String fileName;
Button b_dakai = new Button("打開");
TextArea text = new TextArea();
wenjian() {
super("文件的打開");
setBounds(400, 200, 400, 300);
b_dakai.addActionListener(this);
add(text);
add(b_dakai, "South");
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b_dakai) {
open.show();
fileName = open.getDirectory() + open.getFile();
if (fileName != null) {
readFile(fileName);
}
}
}
// 這是一個打開文件文件的方法
public void readFile(String fileName) {
try {
File file = new File(fileName);
FileReader readIn = new FileReader(file);
int size = (int) file.length();
int charsRead = 0;
char[] content = new char[size];
while (readIn.ready()) {
charsRead += readIn.read(content, charsRead, size - charsRead);
}
readIn.close();
text.setText(new String(content, 0, charsRead));
}
catch (IOException e) {
System.out.println("Error Opening file");
}
}
public static void main(String args[]) {
new wenjian().addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
};
});
;
}
}
② java做web開發,如何設置一個按鈕選擇文件下載的本地路徑,求大神指導
這個簡單<input type="file" value="瀏覽"/>
③ java jquery 點擊按鈕選擇文件,直接傳後台處理
使用ajaxfileupload.js插件
通過AJAX構造表單提交文件
給你一個人家寫好的回JAVA演示調用答地址:
http://www.blogjava.net/sxyx2008/archive/2010/11/02/336826.html