因此,我尝试使用HttpClient从公司网络中的远程txt文件读取。没有防火墙或任何阻止我的请求的东西。这是我的代码:
try{
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("file://hostname/facility_data/Facility_Extract.txt");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
BufferedReader in = new BufferedReader((new InputStreamReader(entity.getContent())));
String input;
while ((input = in.readLine()) != null) {
LOG.info(input);
}
in.close();
}catch(Exception e){
LOG.error("Could not access files : "+e.getMessage());
}
我认为这与'file://'协议有关,但是我不确定如何调整以适应该要求。有什么想法吗?