我的投入文件认为:
1,2,3,4,5,6
3,4,5,6,7,8
5,6,7,8,9,9
1,2,3,4,5,6
我想一栏中一字数和行数,以便我能够知道阵列的规模,将其归入2D阵列。
How can I get the number of column and rows? Thanks!!!!
我的法典:
public static void main(String[] args) throws IOException {
File file = new File("test.txt");
Scanner input = new Scanner(file);
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
int i = 0;
int j = 0;
int row = 0;
int col = 0;
String [][] data = new String [i][j];
while((line = bufRdr.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(file,",");
while (st.hasMoreTokens()){
i++;
}
while(input.hasNextLine()) {
String tmp=input.nextLine();
j++;
}
System.out.println(i);
System.out.println(j);