In java, how to read a file composed of integers and store it in an array?

I'll join in the fun

Look, upstairs is almost ready. But none of them are complete

I'll write a complete one, hehe. I'm too lazy to take notes.

If you have any questions, we can learn from each other:

QQ:254787635 E-mail:zlin@scschina.com

My test data is (there can be non-numbers, any number of blank lines, any number of non-blank lines and any number of columns, and the tt.txt file is required for disk D):

1 3 4 9 0 8 33 df

3 5 2 45 2 1

4 3 8 9 China vs. Iraqi 6 7

3 4 0 China Champions League 3 2 7

1 2 4 1 8 2

4 7 5 8 0 9

The code is as follows:

The package has no title1;

Import java.util.list;

Import java.util.ArrayList;

Import java.io.file;

Import java.io.fileinputstream;

Import java.io.bufferedreader;

Import java.io. *;

Import java.util.regex.pattern;

Import java.util.regex.matcher;

Unnamed public class 1 {

Public untitled 1() {

}

Public static void main(String[] args) {

string FILE _ NAME = " D:\ \ TT . txt ";

untitled 1 untitled 1 = new untitled 1();

list list = untitled 1 . readfile(FILE _ NAME);

int[][]endArray = untitled 1 . get array(list);

untitled 1 . display result(endArray);

}

private void display result(int[][]int array){

System.out.println(

"= = = = = = = = = = = = = = = = = Result = = = = = = = = = = = = = = = = = = = = = = = = = =";

for(int I = 0; I & ltintArray.lengthi++) {

for(int j = 0; j & ltintArray[i]。 Length; j++) {

system . out . print(int array[I][j]+" \ t ");

}

system . out . println(" \ n ");

}

}

private int[][]get array(List List){

int[][]int array = null;

if (list == null) {

Returns null

}

int array = new int[list . size()][];

String tempString =

int count = 0;

string[]tempArray = null;

for(int I = 0; I< list. size (); i++) {

tempString = list.get(i)。 toString()。 trim();

if(tempString = = null | | tempString . length()& lt; = 0) {

Continue;

}

tempArray = tempstring . split(" ");

count = 0;

for(int j = 0; j & lttempArray.lengthj++) {

if (tempArray[j] == null ||

tempArray[j]。 Trim (). length()& lt; = 0 ||

this . isnumeric(tempArray[j]){

Continue;

}

count++;

}

int array[I]= new int[count];

count = 0;

for(int j = 0; j & lttempArray.lengthj++) {

if (tempArray[j] == null ||

tempArray[j]。 Trim (). length()& lt; = 0 ||

this . isnumeric(tempArray[j]){

Continue;

}

int array[I][count]= integer . parse int(tempArray[j]);

count++;

}

}

Return to the array;

}

Private list readFile (string file name)

List & lt string & gtlist = new ArrayList & lt string & gt ();

File file = new file (file name);

If (! file.exists()) {

Return order;

}

Try {

FileReader FileReader = new FileReader(file);

buffered reader buffer reader = new buffered reader(file reader);

String temp =

for(temp = buffer reader . readline();

Temporary workers! = null

temp = bufferReader.readLine()) {

if (temp.trim()。 length()>; 0) {

list . add(temp);

}

}

buffer reader . close();

filereader . close();

} catch(file not found exception ex){

ex . printstacktrace();

} catch (IOException ex) {

ex . printstacktrace();

}

Return order;

}

public boolean is numeric(String str){

pattern pattern = pattern . compile("[0-9]*);

matcher is num = pattern . matcher(str);

If (! isNum.matches()) {

Return true

}

Returns false

}

}