JFileChooser類吧,在按鈕監聽器ActionListener的actionPerformed()方法里添加以下代碼就可以了,這樣一點擊這個按鈕,就會彈出來:
JFileChooser chooser = new JFileChooser();
// DIRECTORIES_ONLY就是只選目錄
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int r = chooser.showOpenDialog(null);
❷ java打開文件對話框
1."public static void main()"是靜態函數,所以不能用this引用。
2.你的OpenFile類應該繼承java.awt.Dialog或者java.awt.Frame.
❸ java 自己定義的打開文件對話框 文件和路徑格式
貌似swing組建里有對話框啊!!
限制格式只要在得到文件路徑以後,截取字元串得到後綴就可以解決了~~
❹ java中關於打開保存文件對話框,並把路徑顯示在JTextField中程序問題
FileDialog.SAVE 用於選擇路徑並保存
FileDialog.LOAD 用於選擇文件
創建FileDialog對象的時候,帶的參數不同,功能也就不一樣。
❺ JAVA程序中點擊按鈕打開文件對話框
1.打開文件
Dim clsIntCmn As New WxsIntCmn
Dim strpath As String = txtPath.Text
clsIntCmn.Openfile(strpath, Page)
System.Diagnostics.Process.Start(strpath)
2.上傳文件
Public Function Savefile(ByVal strFilepath As String, ByVal Request As HttpFileCollection) As Boolean
Dim bolflag As Boolean = True
Dim uploadedFiles As HttpFileCollection = Request
For i As Integer = 0 To uploadedFiles.Count - 1
Dim userPostedFile As HttpPostedFile = uploadedFiles(i)
Try
'要保存文件的路徑
Dim strPath As String = strFilepath & "\" & _
System.IO.Path.GetFileName(userPostedFile.FileName)
If (userPostedFile.ContentLength > 0) Then
'保存文件
userPostedFile.SaveAs(strPath)
End If
txtPath.Text = strPath
txtDelPath.Text = strPath
Catch ex As Exception
bolflag = False
i = uploadedFiles.Count
End Try
Next
Return bolflag
End Function
這是我曾經寫過的,也已經用過,試試吧!應該可以幫助你的,不過你要改用一下語言
❻ 用Java 如何實現「打開」對話框
import java.awt.FileDialog;
public class Mytest extends java.awt.Frame{
public static void main(String args[]) {
FileDialog fd=new FileDialog(new Mytest(),"打開文件");
fd.setVisible(true);
fd.setFile("*.*");
}
}
這樣就可以啊
❼ java 文件打開對話框、
public void Duqu() {
FileReader fr;
try {
fr = new FileReader(".\\data\\dk.txt");
BufferedReader br = new BufferedReader(fr);
try {
String line = br.readLine();
yh.setText(line.toString().substring(0,line.toString().indexOf('-')));
mm.setText(line.toString().substring(line.toString().indexOf('-')+1,line.toString().indexOf('+')));
//System.out.print(line);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
這是我的一段代碼你可以參考下
我沒時間給你解答了,抱歉
❽ Java用輸出流下載文件的時候如何直接彈出(打開)保存對話框
你好,請看下這段程序
<%
response.setCharacterEncoding("gb2312");
request.setCharacterEncoding("gb2312");
if (request.getParameter("file") != null) {
OutputStream os = null;
FileInputStream fis = null;
try {
String file = request.getParameter("file");
if (!(new File(file)).exists()) {
System.out.println("沒有文件");
return;
}
System.out.println("文件名為:"+file);
os = response.getOutputStream();
response.setHeader("content-disposition", "attachment;filename=" + file);
response.setContentType("application/vnd.rn-realmedia-vbr");//此項內容隨文件類型而異
byte temp[] = new byte[1000];
fis = new FileInputStream(file);
int n = 0;
while ((n = fis.read(temp)) != -1) {
os.write(temp, 0, n);
}
} catch (Exception e) {
out.print("出錯");
} finally {
if (os != null)
os.close();
if (fis != null)
fis.close();
}
out.clear();
out = pageContext.pushBody();
}
%>
<form action="" method="post">
<select name="file">
<option value="C:\\Downloads\\冷山\\冷山.rmvb">
冷山
</option>
</select>
<input type="submit">
</form>