下面代码是从a.txt中读取内容并且输出,且输出想要截取的内容。
直接甩代码:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
public class ReadTxt {
// @Autowired
// public static StockInfoMapper stockInfoMapper;
public static void main(String[] args) {
String file_name = "C:/Users/Administrator/Desktop/a.txt";
readFileByLines(file_name);
}
public static void readFileByLines(String fileName)
{
BufferedReader reader = null;
try{
System.out.println("以行为单位读取txt");
reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "gbk"));
String tempString = null;
int line = 1;
Pattern p = Pattern.compile("(?<=com\\/).*?(?=\\.html)&#