현재 위치 - 주공해몽공식사이트 - 랜덤 번호 뽑기 점술 - Java 에서 정수로 구성된 파일을 어떻게 읽고 배열에 저장합니까?

Java 에서 정수로 구성된 파일을 어떻게 읽고 배열에 저장합니까?

나도 와서 떠들어대겠다

보세요, 위층이 거의 다 됐어요. 하지만 아무도 완전하지 않습니다.

나는 완전한 것을 하나 쓸게, 허허. 나는 필기를 하기에는 너무 게으르다.

질문이 있으시면 서로 배울 수 있습니다.

Qq: 254787635e-mail: zlin @ scschina.com

내 테스트 데이터는 (숫자가 아닌 숫자, 빈 행 수, 비어 있지 않은 행 수, 열 수, D 디스크에 tt.txt 파일이 필요할 수 있음) 입니다.

1 3 4 9 0 8 33 df

3 5 2 45 2 1

4 3 8 9 중국팀 대 이라크 6 7

3 4 0 중국 챔피언스 리그 3 2 7

1 2 4 1 8 2

4 7 5 8 0 9

코드는 다음과 같습니다.

패키지에는 제목이 없습니다1;

Java.util.list 가져오기

Java.util.arraylist 가져오기

Java.io.file 을 가져옵니다

Java.io.fileinputstream 가져오기

Java.io.bufferedreader 가져오기

Java.io. *;

Java.util.regex.pattern 을 가져옵니다.

Java.util.regex.matcher 를 가져옵니다.

이름 없는 공용 클래스 1 {

공용 제목 없음 1() {

}

공용 정적 void main(String[] args) {

String file _ name = "d: \ \ tt.txt";

Untitled1untitled1= newuntitled1();

Listlist = untitled1.readfile (file _ name);

Int [] [] end array = untitled1.getarray (list);

Untitled1.display result (end array);

}

Private void displayresult (int [] [] int array) {

System.out.println (

"= = = = = = = = = = = = = = = = = = = = = = = 결과 = = = = = = = = = = = = = = = = = = =

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

For(int j = 0;; J & ltintArray[i]. 길이; J++) {

System.out.print (intarray [I] [j]+"\ t");

}

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

}

}

Privateint [] [] getarray (목록 목록) {

Int [] [] intarray = null;

If (list == null) {

Null 을 반환합니다

}

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

String tempString =

Intcount = 0;

String[]tempArray = null;;

For(int I = 0;; 나 & ltlist.size (); I++) {

TempString = list.get(i) 입니다. ToString (). Trim ();

If (tempstring = = null | | tempstring.length () < = 0) {

계속;

}

Temparray = tempstring.split ("");

Count = 0;;

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

If (tempArray[j] == null ||

TempArray[j]. 자르기 (). 길이 () < = 0 ||

This. isnumeric(tempArray[j]){

계속;

}

Count++;+;

}

Intarray [I] = new int [count];

Count = 0;;

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

If (tempArray[j] == null ||

TempArray[j]. 자르기 (). 길이 () < = 0 ||

This. isnumeric(tempArray[j]){

계속;

}

Intarray [I] [count] = integer.parseint (temparray [j]);

Count++;+;

}

}

배열로 돌아가기

}

개인 배포 목록 readFile (문자열 파일 이름) {

목록< 문자열 & gtlist = new ArrayList & lt 문자열> ();

File file = 새 파일 (파일 이름);

만약 (! File.exists()) {

반품 양식

}

시도 {

Filereader filereader = new filereader (파일);

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

String temp =

For (temp = bufferreader.readline ();

임시직! = null

Temp = bufferReader.readLine()) {

If (temp.trim ()) 입니다. 길이 () >; 0) {

List.add (temp);

}

}

Bufferreader.close ();

Filereader.close ();

} catch (file not found exception ex) {

Ex.printstacktrace ();

} catch (IOException ex) {

Ex.printstacktrace ();

}

반품 양식

}

Public boolean is numeric (stringstr) {

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

Matcher isnum = pattern.matcher (str);

만약 (! IsNum.matches()) {

True 를 반환합니다

}

False 를 반환합니다

}

}