2011-01-25 6 views
1

私は、ファイルをダウンロードした後、ftp経由でファイルをダウンロードするためのjavaコードを持っています。デフォルトのパスになります。指定された宛先パスにダウンロードされたファイルがありません。どうして? ":/ rvenktesan /ソフトウェアD" 私のコードは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:rvenkatesan/JAVA PROJECTS」にあります。どうして?特定のパスにファイルを保存するように案内しますか?広告に感謝します。

+0

まだ私の問題は解決していません.... – Venkat

+0

私は解決策を得ました。 'destination.getName()'の代わりにFileInputStream(destination.getAbsoluteFilePath())を使用します。ご返事ありがとうございます。 – Venkat

答えて

1

あなたの問題があるFileOutputStream(destination.getName())); 変更するには、この:のgetNameは、ファイル名 "ddd.txt" のみを返すウィルFileOutputStream(destination.getAbsolutePath()));

。私はあなたのアプリを起動していると仮定しますD:/rvenkatesan/JAVA PROJECTS

関連する問題