发一个读取TXT文件数据的程序代码
package business;import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;
public class TXTReader {
protected String matrix[][];
protected int xSize;
protected int ySize;
public TXTReader(String sugarFile) {
java.io.InputStream stream = null;
try {
stream = new FileInputStream(sugarFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
init(in);
}
private void init(BufferedReader in) {
try {
String str = in.readLine();
if (!str.equals("b2")) {
throw new UnsupportedEncodingException(
"File is not in TXT ascii format");
}
str = in.readLine();
String tem[] = str.split("[\\t\\s]+");
xSize = Integer.valueOf(tem).intValue();
ySize = Integer.valueOf(tem).intValue();
matrix = new String;
int i = 0;
str = "";
String line = in.readLine();
while (line != null) {
String temp[] = line.split("[\\t\\s]+");
line = in.readLine();
for (int j = 0; j < ySize; j++) {
matrix = temp;
}
i++;
}
in.close();
} catch (IOException ex) {
System.out.println("Error Reading file");
ex.printStackTrace();
System.exit(0);
}
}
public String[][] getMatrix() {
return matrix;
}
} 请问楼主,有没有能把repast中的一个变量写入到一个txt文档的程序呢?
页:
[1]