【发布时间】:2014-07-21 13:49:26
【问题描述】:
在制作桌面应用程序时,我希望它能够从服务器下载视频文件并将其保存在客户端的 PC 中。 怎么做?我不知道。 使用什么工具?请指导 我期待某种集成的 FTP 之类的东西。我不清楚它是如何工作的。
【问题讨论】:
-
最简单的方法可能是
URLConnection。
标签: java desktop-application netbeans-platform
在制作桌面应用程序时,我希望它能够从服务器下载视频文件并将其保存在客户端的 PC 中。 怎么做?我不知道。 使用什么工具?请指导 我期待某种集成的 FTP 之类的东西。我不清楚它是如何工作的。
【问题讨论】:
URLConnection。
标签: java desktop-application netbeans-platform
您想在哪里下载文件?直接网址或youtube之类的?
类似的东西:
public class DownloadToFile
{
private URL from;
private String to;
public DownloadToFile(URL url, String path_to)
{
this.URL = url;
this.to = path_to;
}
public DownloadToFile(String url, String path_to)
{
try
{
this.URL = new URL(url);
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
this.to = path_to;
}
public void saveFile() throws IOException
{
BufferedInputStream in = new BufferedInputStream(this.from.openStream());
FileOutputStream out = new FileOutputStream(this.to);
try
{
final byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1)
{
out.write(data, 0, count);
}
}
finally
{
if (in != null)
{
in.close();
}
if (fout != null)
{
fout.close();
}
}
}
【讨论】: