我的部分代码如下,存可以,但是load的时候读不出来
存
TextFile outfile = new TextFile();
outfile.add("# Created at " + (new Date()));
outfile.add("");
outfile.add("_NUM3D: "+num3d);
outfile.add("_NUM4D: "+num4d);
取:
public void load(String filename) {
try {
this.setFileName(filename);
TextFile infile = new TextFile(filename);
String line = new String();
for (int i = 0; i < infile.size(); i++) {
line = (String) infile.get(i);
if (line.matches("^[ \t\f]*(#+).*") || line.matches("^[ \t\f]*")) {
continue;
}
line = line.trim();
String flag = (line.split("[ \t\f\r\n]+"))[0];
if (flag.equals("_NUM3D: ")) {
String str = (line.split("_NUM3D: "))[1];
str.trim();
this.num3d = Integer.parseInt(str);
System.out.println(num3d);
continue;
}
if (flag.equals("_NUM4D: ")) {
String str = (line.split("_NUM4D: "))[1];
str.trim();
this.num4d = Integer.parseInt(str);
continue;
}
------解决方案--------------------
首先确认下line是否有值,有的话就是split的正则有问题
------解决方案--------------------
split的正则有问题
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
就是你匹配的正则表达式有问题