導航:首頁 > 編程語言 > 打開文件對話框java

打開文件對話框java

發布時間:2023-01-21 09:55:35

❶ 【java】如何實現「打開文件夾」對話框

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>

閱讀全文

與打開文件對話框java相關的資料

熱點內容
單片機程序存儲c 瀏覽:489
賽高網解壓密碼 瀏覽:775
雲伺服器安裝賺錢寶 瀏覽:107
pdf能修改內容嗎 瀏覽:386
貸款辦下來不給解壓 瀏覽:141
德國頂級編程思路 瀏覽:852
Flt單片機 瀏覽:476
ami和hdb3編解碼對比 瀏覽:665
純手工製作解壓視頻 瀏覽:119
雲職教APP為什麼收不到驗證碼 瀏覽:697
禮品發包網源碼 瀏覽:569
什麼app上能制圖 瀏覽:86
為什麼代理伺服器沒響應 瀏覽:562
小程序編譯提示 瀏覽:824
nameerrorpython 瀏覽:294
辭典pdf下載 瀏覽:801
遺傳演算法違反約束路徑數目 瀏覽:177
少年班中的古人演算法 瀏覽:931
什麼app一鍵p圖好看 瀏覽:573
查詢手機連上電腦的命令 瀏覽:850