读入文件的格式
9 9 9 9 0 0 0 0
9 9 9 0 0 0 0 0
0 9 9 0 7 7 0 0
0 0 0 0 7 7 0 0
0 0 0 0 7 7 7 7
0 0 0 0 7 7 7 7
0 0 0 0 7 7 7 7
0 0 0 0 7 7 7 7
程序
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class cetu2{
public static void main(String arg[]) throws IOException{
int b,n,k,count,p;
n=0;
k=0;
double m;
m=0;
count = 0;
byte g[] = new byte [60];
int a[] = new int[20];
int shou[] = new int[60];
int jie[] = new int[60];
String str = null;
String st[] = new String[20];
String tr = null;
FileReader f = null;
FileWriter file = null;
try {
f = new FileReader("111OK.txt");
file = new FileWriter("000.txt");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
BufferedReader in = null;
BufferedWriter out = null;
out = new BufferedWriter(file);
in = new BufferedReader(f);
tr = in.readLine();
str = tr.replaceAll(" ","");
System.out.println(str);
}
}
因为你的正则表达式写错了,分析文本可以知道,要匹配的是制表符\t 而不是空格
str = tr.replaceAll(" ","");修改成
str = tr.replaceAll("\t","");完整的代码修改
import java.io.BufferedReader;