import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import junit.framework.TestCase;
public class FileReadNet extends TestCase {
public void testName() throws IOException {
URL url = new URL("http://www.imooc.com/article/12061");
URLConnection connection = url.openConnection();
connection.connect();
InputStream inputStream = connection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
StringBuilder builder = new StringBuilder(1024);
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
builder.append("\r\n");
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
line = builder.toString();
int index = line.indexOf("<code>") + "<code>".length();
int lastIndex = line.lastIndexOf("</code>");
line = line.substring(index, lastIndex);
line = line.replaceAll("<", "<").replaceAll(">", ">");
System.out.println(line);
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦