hi. could some one help me. I am trying to read the tokens into the array but the datatypes are incompatible. what should i do to cast it into the same thing. the numbers from my text file are actually floats. But i can make do with just the integers if it aint possible.
import java.util.*;
import java.io.*;
public class BasisGenesis {
//variables
//Mu (the model structures)
public static void main(String[] args) //main method
{
File dir = new File("1a00.gz.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];
int count = 0;
try
{
BufferedReader in = new BufferedReader(new FileReader(fileDir[j]));
String str;
while ((str = in.readLine())!=null)
{
StringTokenizer s = new StringTokenizer(str," ");
int counter=0; //every line has 2 tokens
String line="";
//2D intialising
int row = 0;
int col = 0;
int [][] array = null;
while(s.hasMoreTokens())
{
String ss = s.nextToken();
counter++;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//read into 2D array
if (counter==1)
{
row = Integer.parseInt(ss);//take the first line and put into the row:
}
else if (counter == 2)
{
//take the second line and put it into the col:
col = Integer.parseInt(ss);
array = new int[row][col];
}
}//end of while
System.out.println(line);
line +="\0";
}//end of while
in.close();
}//end of try
catch (IOException e) { }
}//end of for
}//end of else
}//end of main method
thanks much!!!!