2013-01-21 2 views
0

이 코드를 사용하여 pdb 웹 사이트에서 fasta 시퀀스 파일을 다운로드하고 있습니다. pdb id는 protid 문자열입니다.Fasta 파일을 다운로드하여 텍스트 파일에 작성하십시오.

import java.io.*; 
import java.net.URL; 
import java.util.Scanner; 

public class Trialoffile 
{ 

    public static void main(String[] args){ 

     InputStream url; 

     String protID="2ly4"; 


     try{ 


       url = new URL("http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=FASTA&compression=NO&structureId="+protID).openStream(); 
       Scanner fasta = new Scanner(url); 

       BufferedWriter bw= new BufferedWriter(new FileWriter(protID+".txt", true)); 




       //output file is prepared. 

       while(fasta.hasNextLine()){ 

       bw.write(fasta.nextLine()+"\n"); 

       } 
       } 





     catch (Exception e) 
     { 
      System.err.println("File input error on:"+protID); 
     } 
    } 

} 

오류는 발생하지 않지만 기록되는 파일은 0 바이트입니다. 같은 사이트에서 다른 형식의 다른 파일을 다운로드하려고 시도했지만 문제가 없습니다.

답변

0

완료 후 작성자를 플러시하고 닫는 것을 잊지 마십시오!

bw.flush(); 
bw.close(); 
0

끝에 파일을 닫아보십시오.

while(fasta.hasNextLine()){ 

     bw.write(fasta.nextLine()+"\n"); 

} 
bw.close(); 
관련 문제