输入url地址读取txt文件
/**
* Created by qqg on 2018/1/3.
*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class w {
private static 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;
}
public static void main (String[] args){ System.out.print(w.openFile("http://******/hrmsstatic/SensitiveWord.txt" ));
}
}