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);
}
}
打开App,阅读手记