Hi all
Im experiencing problems whereby my codes can only read one file instead of all files in my directory. Does anyone know anything regarding this?
Below are my codes:
import java.io.*;
import java.util.*;
public class extractionn
{
public static void main( String[] args )
{
File dir = new File("D:\\project1\\MP Project\\Database\\Extracted\\binding protein\\1APB.pdb.txt"); //set file
String path = dir.getAbsolutePath(); //get file path
int lala = path.lastIndexOf("\\"); //get index of '\'
String howPath = path.substring(0,lala+1); //extract directory name
File usePath = new File(howPath); //assign directory for reading file
String[] fileDir = usePath.list(); //store file in dit to array
if(fileDir == null) //check if dir exists
{
System.out.println("Directory Does Not Exist");
}
else
{
for(int j=0; j<fileDir.length;j++)
{
String fileName = fileDir[j];
try
{
BufferedReader in = new BufferedReader(new FileReader(fileDir[j])); //reading files in specified directory
//FileWriter outStream = new FileWriter ("D:\\project1\\MP Project\\Protein Database\\" +fileName +".txt"); //location of files created & naming of files
String str;
while ((str = in.readLine()) != null) //file reading
{
if ((str.trim().startsWith("ATOM") && str.trim().endsWith("C"))) //extract lines that starts with ATOM AND end with anything but H
{
String[] store = new String[10000];
int z =0;
StringTokenizer s = new StringTokenizer(str," ");
int counter=0;
String line="";
while(s.hasMoreTokens())
{
String ss = s.nextToken();
counter++;
if (counter ==3 || counter==4)
{
line += ss;
line +=" ";
}//end of if (counter ==3 || counter==4)
}//end of while(s.hasMoreTokens())
if(line.trim().startsWith("CA"))
{
if(line.trim().endsWith("ALA"))
{
System.out.print("A");
store[z]= "A";
z++;
}//end of if(line1.trim().startsWith("ALA"))
if(line.trim().endsWith("ARG"))
{
System.out.print("R");
store[z]= "R";
z++;
}//end of if(line1.trim().startsWith("ARG"))
if(line.trim().endsWith("ASN"))
{
System.out.print("N");
store[z]= "N";
z++;
}//end of if(line1.trim().startsWith("ASN"))
if(line.trim().endsWith("ASP"))
{
System.out.print("D");
store[z]= "D";
z++;
}//end of if(line1.trim().startsWith("ASP"))
if(line.trim().endsWith("CYS"))
{
System.out.print("C");
store[z]= "C";
z++;
}//end of if(line1.trim().startsWith("CYS"))
if(line.trim().endsWith("GLN"))
{
System.out.print("Q");
store[z]= "Q";
z++;
}//end of if(line1.trim().startsWith("GLN"))
if(line.trim().endsWith("GLU"))
{
System.out.print("E");
store[z]= "E";
z++;
}//end of if(line1.trim().startsWith("GLU"))
if(line.trim().endsWith("GLY"))
{
System.out.print("G");
store[z]= "G";
z++;
}//end of if(line1.trim().startsWith("GLY"))
if(line.trim().endsWith("HIS"))
{
System.out.print("H");
store[z]= "H";
z++;
}//end of if(line1.trim().startsWith("HIS"))
if(line.trim().endsWith("ILE"))
{
System.out.print("I");
store[z]= "I";
z++;
}//end of if(line1.trim().startsWith("ILE"))
if(line.trim().endsWith("LEU"))
{
System.out.print("L");
store[z]= "L";
z++;
}//end of if(line1.trim().startsWith("LEU"))
if(line.trim().endsWith("LYS"))
{
System.out.print("K");
store[z]= "K";
z++;
}//end of if(line1.trim().startsWith("LYS"))
if(line.trim().endsWith("MET"))
{
System.out.print("M");
store[z]= "M";
z++;
}//end of if(line1.trim().startsWith("MET"))
if(line.trim().endsWith("PHE"))
{
System.out.print("F");
store[z]= "F";
z++;
}//end of if(line1.trim().startsWith("PHE"))
if(line.trim().endsWith("PRO"))
{
System.out.print("P");
store[z]= "P";
z++;
}//end of if(line1.trim().startsWith("PRO"))
if(line.trim().endsWith("SER"))
{
System.out.print("S");
store[z]= "S";
z++;
}//end of if(line1.trim().startsWith("SER"))
if(line.trim().endsWith("THR"))
{
System.out.print("T");
store[z]= "T";
z++;
}//end of if(line1.trim().startsWith("THR"))
if(line.trim().endsWith("TRP"))
{
System.out.print("W");
store[z]= "W";
z++;
}//end of if(line1.trim().startsWith("TRP"))
if(line.trim().endsWith("TYR"))
{
System.out.print("Y");
store[z]= "Y";
z++;
}//end of if(line1.trim().startsWith("TYR"))
if(line.trim().endsWith("VAL"))
{
System.out.print("V");
store[z]= "V";
z++;
}//end of if(line1.trim().startsWith("VAL"))
if(store[z] != null)
System.out.println(store[z]+"\t");
}//end of if(line.trim().startsWith("CA"))
}
}
//outStream.close(); //closing of writer
in.close(); //closing of reader
} catch (IOException e) { } //try & catch
} //end of for loop
} //end of else
} //end of method
}
//end of class