public static void main(String[] args)throws Exception { File f = new File("1.txt"); byte[] b = new byte[(int) f.length()]; FileInputStream fi = new FileInputStream(f); fi.read(b); String s = new String(b); String[] sd = s.split("(?m)^\\s*}$"); System.out.println(sd.length); for(int i=0;i<sd.length;i++){ System.out.println(sd[i]); System.out.println("----------------------"); } }
String[] sd = s.split("(?m)^\\}$"); 如果分割符里,不写(?m),可以在java里设定多行模式。 String[] sd =Pattern.compile("^\\}$",Pattern.MULTILINE).split(s); from javadoc
public static void main(String[] args)throws Exception {
File f = new File("1.txt");
byte[] b = new byte[(int) f.length()];
FileInputStream fi = new FileInputStream(f);
fi.read(b);
String s = new String(b);
String[] sd = s.split("(?m)^\\s*}$");
System.out.println(sd.length);
for(int i=0;i<sd.length;i++){
System.out.println(sd[i]);
System.out.println("----------------------");
}
}
如果分割符里,不写(?m),可以在java里设定多行模式。
String[] sd =Pattern.compile("^\\}$",Pattern.MULTILINE).split(s);
from javadoc