话不多说直接提供方法
private String openFile(String filePath) {
int HttpResult;
String ee = new String();
try {
URL url = new URL(filePath);
URLConnection urlconn = url.openConnection();
urlconn.connect();
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
HttpResult = httpconn.getResponseCode();
if (HttpResult != HttpURLConnection.HTTP_OK) {
System.out.print("无法连接到");
} else {
int filesize = urlconn.getContentLength();
InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(isReader);
StringBuffer buffer = new StringBuffer();
String line;
line = reader.readLine();
while (line != null) {
buffer.append(line);
buffer.append(" ");
line = reader.readLine();
}
System.out.print(buffer.toString());
ee = buffer.toString();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ee;
}