请问如何写一个Java程序读取DAT文件里的内容

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:58:02
111111
11100e
100011
110m01
111111
以上是kkk.dat 里的内容
读完后把它放进一个2维数组里 一共5行 每行6个

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Test4 {
public static void main(String[] args) {
String[][] arr=new String[5][6];
String fileName="c:/a.dat";
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
char[] temp=null;
int line=0;
while ((tempString = reader.readLine()) != null) {
temp=tempString.toCharArray();
for (int i = 0; i < temp.length; i++) {
arr[line][i]=temp[i]+"";
}
line+=1;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e1) {
}
}
System.out.println("数组显示:");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 6; j