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>