2011-01-25 2 views
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(); 
    } 
    } 

    } 
     } 

     } 

"D :/rvenktesan/Software"에없는 파일 "ddd.txt"입니다. "D : rvenkatesan/JAVA PROJECTS"에 있습니다. 왜? 지정된 경로에 파일을 저장하도록 안내합니까? 광고에 감사드립니다.

+0

아직도 나의 문제는 해결되지 않는다. ... – Venkat

+0

예. 나는 해결책을 얻었다. 'destination.getName()'대신 FileInputStream (destination.getAbsoluteFilePath())에서. ur 답장을 보내 주셔서 감사합니다. – Venkat

답변

1

당신의 문제는 FileOutputStream(destination.getName())); 변화에이 : getName 파일 이름 "ddd.txt"만 돌려 줘야 FileOutputStream(destination.getAbsolutePath()));

. 나는 당신이 당신의 앱을 시작한다고 가정한다. D:/rvenkatesan/JAVA PROJECTS