1
我有用于通过ftp下载文件的java代码,下载文件后它会转到默认路径。指定的目标路径没有下载的文件。为什么?我的代码,ftp文件下载路径有问题?
public class ftpUpload1
{
public static void main(String a[]) throws IOException
{
ftpUpload1 obj = new ftpUpload1();
URL url1 = new URL("ftp://vbalamurugan:[email protected]/ddd.txt");
File dest = new File("D:/rvenkatesan/Software/ddd.txt");
obj.ftpDownload(dest, url1);
public void ftpDownload(File destination,URL url) throws IOException
{
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URLConnection urlc = url.openConnection();
bis = new BufferedInputStream(urlc.getInputStream());
bos = new BufferedOutputStream(new
FileOutputStream(destination.getName()));
int i;
//read byte by byte until end of stream
while ((i = bis.read())!= -1)
{
// bos.write(i);
bos.write(i);
}
System.out.println("File Downloaded Successfully");
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}
}
下载的文件 “ddd.txt” 不在 “d:/ rvenktesan /软件”。它位于“D:rvenkatesan/JAVA PROJECTS”。为什么?指导我将文件存储在指定的路径中?非常感谢。
开始你的应用程序仍然我的问题是不解决.... – Venkat 2011-01-25 10:58:15