1. java如何實現下載彈出的對話框
Java實現點擊下載文件的時候,彈出「另存為」對話框,選擇保存位置,然後下載,代碼如下:
publicvoiddownLoad(StringfilePath,HttpServletResponseresponse)
throwsException{
System.out.println("filePath"+filePath);
Filef=newFile(filePath);
if(!f.exists()){
response.sendError(404,"Filenotfound!");
return;
}
BufferedInputStreambr=newBufferedInputStream(newFileInputStream(f));
byte[]buf=newbyte[1024];
intlen=0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;filename="+f.getName());
OutputStreamout=response.getOutputStream();
while((len=br.read(buf))>0)out.write(buf,0,len);
br.close();
out.close();
}
2. 每次開機都出現這個對話框,怎麼解決啊電腦已安裝了java程序
下載一個JDK安裝,然後按照下面的配置就好了。。記得要下載32位的
%EXE4J_JAVA_HOME%;%EXE4J_JAVA_HOME%in;
3. 用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("*.*");
}
}
這樣就可以啊