Current location - Training Enrollment Network - Mathematics courses - How to read the matrix in txt file with java
How to read the matrix in txt file with java
//Initialize the array for storing txt data.

String[][]rows = new String[ 10][ 10];

int index = 0;

BufferedReader br = null

Try {

//Read the file. The path is the txt file path.

br = new buffered reader(new File reader(new File(" D:\ \ valued _ book \ \ juzhen . txt "));

String str = null

//Read line by line

while((str=br.readLine())! =null){

//Maybe the number of spaces between two numbers is not fixed, and it can be n 。

rows[index]= str . split("()+");

index++;

}

//Print out the results

for (String[] strings : rows) {

For (string string: string) {

System.out.println ("Everything you think is here:"+string);

}

}

} catch(file not found exception e){

// TODO automatically generated catch block

e . printstacktrace();

} catch (IOException e) {

// TODO automatically generated catch block

e . printstacktrace();

}