㈠ 用java流的方式怎么指定下载到指定目录下
举例代码:
/**
*下载文件。
*@文件的URL
*@paramsavePath保存到的目录
*@paramfileName保存的文件名称
*@paramdescription描述(如:歌曲,专辑封面,歌词等)
*@throwsIOException
*/
publicstaticvoiddownLoad(StringurlStr,StringsavePath,StringfileName,Stringdescription)throwsIOException
{
URLurl=newURL(urlStr);
HttpURLConnectionconn=(HttpURLConnection)url.openConnection();
conn.setConnectTimeout(100000);//设置超时间为10秒
conn.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE5.0;WindowsNT;DigExt)");//防止屏蔽程序抓取而返回403错误
FilesaveDir=newFile(savePath);
Filefile=newFile(saveDir+File.separator+fileName);
try(InputStreaminputStream=conn.getInputStream();
FileOutputStreamfos=newFileOutputStream(file))
{
byte[]flowData=readInputStream(inputStream);
fos.write(flowData);
}catch(Exceptione){
MainFrame.logEvent("字节保存时出现意外:"+e.getMessage());
}
MainFrame.logEvent(description+"下载完成:"+url);
}
MainFrame.logEvent()是我自己弄的日志记录而已,可以忽略不看
㈡ 怎么用Java到指定地址下载东西放到指定文件夹下!
文件夹是默认的,系统设置好的。如果是在卡上的话,你可以用迅雷将下载的文件默认到手机内存卡上的某个文件夹中
㈢ 在java中如何把一个文件放到指定的文件夹中
首先获得fileoutput对象时,写入具体的目录就可以了。
比如:你要写入到d:\java\test目录下。
方法一:
java代码
string
name
=
"out.html";
string
dir
=
"d:\\java\\test";
file
file
=
new
file(dir,name);
fileoutputstream
out
=
new
fileoutputstream(file);
方法二:
java代码
fileoutputstream
out
=
new
fileoutputstream(dir+"\\"+name);
㈣ java程序 如何设置下载文件的保存路径
生成一个文件选择窗口,让用户选择路径
㈤ javaweb如何将文件保存到服务器的指定目录
可以把文件目录配置在web.xml文件的初始化参数中, 通过ServletAPI读取文件目录
比如
定义一个Properties文件保存相关配置
#可以上传文件的后缀名
extensions=pptx,docx.doc,txt,jpg,jar
#单个文件的大小1M
fileMaxSize=1048576
#总共上传文件大小5M
totalFileMaxSize=5242880
#文件保存路径
filePath=z:/temp
#临时文件路径
tempDir=z:/temp/temp
使用Listener在服务器启动时加载配置信息
ServletContextcontext=event.getServletContext();
InputStreaminputStream=context
.getResourceAsStream("/WEB-INF/classes/file/upload/commons/uploadConfig.properties");
Propertiesproperties=newProperties();
try{
properties.load(inputStream);
context.setAttribute("fileConfig",properties);
System.out.println("properties="+properties.size());
}catch(IOExceptione){
e.printStackTrace();
}
在你上传文件时通过配置文件读取路径保存
String filePath = ((Properties) this.getServletContext().getAttribute("fileConfig"))
.getProperty(FileUploadConstants.FILE_PATH);
㈥ java怎么通过链接下载文件,然后保存到指定位置
点击下载,其实就是访问文件路径,通过流读取,然后再指定文件保存位置.还是通过流保存.
file(连接路径)>>input>>out>>file(保存位置)
㈦ java下载文件,怎么指定下载到指定的文件夹下啊,就是不弹出保存框,直接下载到指定的文件夹下,谢谢回答
如果是用 IE 等浏览复器下载制,这些浏览器都有自己的下载目录定义。
如果是你自己用 Java 写了一个浏览器,则在接收到下载流时,用 FileOutputStream fos = new FileOutputStream("d:\\java-browser\\downloads"); 即可。