Hey there!

How do i read 2 files, one after another and then storing it into 2 seperate array?
This is the code for reading 1 file. So, how do I read 2 files? The array would be a 3x3 2D array.

File dir = new File("1A6G.pdb"); 				     	//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{
       	input1 = new BufferedReader(new FileReader(new File(fileDir[j])));
        FileWriter outStream = new FileWriter ("D:\\project1\\exp\\proteins\\" +fileName +".txt");


//rest of code



 } //end of while.
 input1.close();	
           outStream.close();
			}//end of try
			
		
	
			catch( IOException e) {
				e.printStackTrace();
				}//end of catch


    }//end of for loop
}    
}//end of main
}// end of public class

why cant you implement this into separate function and call it with a parameter .
The parameter should be the file name.

Thank you for the reply
I'm very new to Java, so I don't really get the whole parameter concept. Can you explain to me please? :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.