0

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
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by hazeeel
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.