java 读文件,按行读取,将读取的结果放入数组中


import java.io.*;

public class ReadCardType
{
public static void main(String[] args)throws IOException
{
BufferedReader in = null ;
String s = new String();
String cartTypeCode,cardTypeStr;
int index = 0 ,pos=0,i=0;
String[][] cardType ;

in = new BufferedReader(new FileReader("cardtype.cfg"));
while((s = in.readLine()) != null){
index++;
}
cardType = new String[index][2];
in.close();

in = new BufferedReader(new FileReader("cardtype.cfg"));
while((s = in.readLine()) != null)
{
pos = s.indexOf('=');
System.out.println("pos="+pos);
cartTypeCode = s.substring(0,pos);
cardTypeStr = s.substring(pos+1);
System.out.println("cartTypeCode="+cartTypeCode);
System.out.println("cardTypeStr="+cardTypeStr);
cardType[i][0] = cartTypeCode ;
cardType[i][1] = cardTypeStr ;
i++ ;
}
in.close();

for(int j = 0 ;j < index ; j++){
System.out.println("card type:"+cardType[j][0]+cardType[j][1]);
}

}
}

你可能感兴趣的:(java)