Java读取远程服务器上的txt文件

1 public String ReadUrl(String FileName) throws IOException{
2 String read;
3 String readStr ="";
4 try{
5 URL url =new URL(FileName);
6 HttpURLConnection urlCon = (HttpURLConnection)url.openConnection();
7 urlCon.setConnectTimeout(5000);
8 urlCon.setReadTimeout(5000);
9 BufferedReader br =new BufferedReader(new InputStreamReader( urlCon.getInputStream()));
10 while ((read = br.readLine()) !=null) {
11 readStr = readStr + read;
12 }
13 br.close();
14 }
15 catch (IOException e) {
16 // TODO Auto-generated catch block
17 readStr ="f";
18 }
19 return readStr;
20 }
21
原文地址:https://www.cnblogs.com/dumanqingren/p/2025291.html