導航:首頁 > 編程語言 > 打開文件對話框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相關的資料

熱點內容
我的世界如何查看伺服器種子pc 瀏覽:284
linuxlamp編譯安裝 瀏覽:609
枚舉演算法ppt 瀏覽:184
cmd查看進程命令 瀏覽:956
手機內怎麼刪除APP 瀏覽:834
魚群和鳥群演算法區別 瀏覽:93
pdf尺寸設置 瀏覽:211
android訪問本地伺服器 瀏覽:512
程序員相親被刪除微信 瀏覽:790
centos命令窗口 瀏覽:596
編譯器有幾個好用的 瀏覽:500
資料庫和網站如何搭載伺服器 瀏覽:154
網路流理論演算法與應用 瀏覽:795
java和matlab 瀏覽:388
釘釘蘋果怎麼下app軟體 瀏覽:832
php網站驗證碼不顯示 瀏覽:859
鋁膜構造柱要設置加密區嗎 瀏覽:344
考駕照怎麼找伺服器 瀏覽:885
阿里雲伺服器如何更換地區 瀏覽:972
手機app調音器怎麼調古箏 瀏覽:505