2014-02-26 4 views
2

Java에서 .torrent 파일을 다운로드하려고합니다. 나는이 SO (Java .torrent file download) 질문을 들었지만 프로그램을 실행할 때 다운로드를 시작하지 않습니다. 그것은 절대적으로 아무것도하지 않습니다. 누군가 내가 잘못하고있는 것을 나에게 설명 할 수 있습니까? 아래에 SSCCE를 게시했습니다. 고맙습니다..torrent 파일 다운로드 Java

import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.URL; 
import java.nio.channels.Channels; 
import java.nio.channels.ReadableByteChannel; 

public class Test { 
    public static void main(String[] args) throws IOException { 
     String link = "http://torrage.com/torrent/13764753227BCBE3E8E82C058A7D5CE2BDDF9857.torrent"; 
     String path = "/Users/Bob/Documents"; 
     URL website = new URL(link); 
     ReadableByteChannel rbc = Channels.newChannel(website.openStream()); 
     File f = new File(path + "t2.torrent"); 
     FileOutputStream fos = new FileOutputStream(f); 
     fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 
     fos.close(); 
    } 
} 

답변

1

파일 경로를 올바르게 포맷하지 않았습니다. 이것에

File f = new File(path + "t2.torrent"); 

변경을 : 코드의이 부분은 문제가

File f = new File(path + File.separator + "t2.torrent"); 

편집 :

문제가 해결되지 않으면, 당신은 당신의 파일 경로를 해결하려고한다. C:\Users\Bob\Documents과 같은 것이 아닌 것이 확실합니까?

파일 경로가 고정되고 토렌트 파일이 올바르게 다운로드되면 토렌트를로드 할 때 토런트 프로그램에서 오류가 발생하면 토렌트 파일이 GZIP 형식이기 때문에 가능성이 높습니다. 문제를 해결하려면 연결된 질문에 게시 된 솔루션을 따르십시오.

String link = "http://torrage.com/torrent/13764753227BCBE3E8E82C058A7D5CE2BDDF9857.torrent"; 
String path = "/Users/Bob/Documents"; 
URL website = new URL(link); 
try (InputStream is = new GZIPInputStream(website.openStream())) { 
    Files.copy(is, Paths.get(path + File.separator + "t2.torrent")); 
    is.close(); 
} 
+0

그래도 작동하지 않으면 내 경로에 문제가 있습니까? – Joe

+0

업데이트 된 게시물보기. – uyuyuy99

+0

한 가지 더 궁금한 점은, 어떻게하면 내 경로가 더 일반화되어 모든 컴퓨터에서 작동하는지 지금 당장 내 이름이 경로에 있기 때문입니다. – Joe