2017-08-02(正则表达式进行字符串截取)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class io12 {
public static void main(String[] args) throws Exception {
File f=new File("F://FeigeDownload//1.txt"); //创建一个文件
FileInputStream file=new FileInputStream("F://FeigeDownload//1.txt"); //IO流读取文件
int l=(int)f.length(); //获取文件的长度
byte[]b=new byte[l]; //把文件放到数组里
file.read(b); //读文件
Pattern p = Pattern.compile("id(.*?)d=\"(.*?)\""); //正则表达式获取需要文件内容的范围
Matcher m = p.matcher( new String(b,"GBK")); //正则表达式进行匹配
while (m.find()) { //输出
System.out.println(m.group(0));
}
}
}