I am using this code to download a fasta sequence file from the pdb website. The pdb id is the string protid.
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);
}
}
}
I am not getting error but the file written is of 0 bytes. I tried downloading another file of a different format from the same site and had no issues.