java讀取本地文件

public static void 
main(String[] args) {
//        HttpClient client = null;
//        PostMethod postMethod = null;
        
CloseableHttpClient client = HttpClients.
createDefault
();        
try 
{
            String dsmUrl = 
"http://localhost:8888"
;
            String cmd = 
"queryName"
;
            JSONObject arg = 
new 
JSONObject();
            File file = 
new 
File(
"D:
\\
2345下載
\\
system.json"
);
            FileInputStream fis = 
new 
FileInputStream(file);
            InputStreamReader isr = 
new 
InputStreamReader(fis);
            BufferedReader br = 
new 
BufferedReader(isr);
            String value = 
null
;
            StringBuffer string = 
new 
StringBuffer();            
while 
((value = br.readLine()) != 
null
){
                string.append(value);
            }
//            System.out.println(string);
            
arg = JSON.
parseObject
(string.toString());
            arg = arg.getJSONObject(
"s2"
);
            String query = 
"cmd=" 
+ cmd + 
"&&arg=" 
+ arg;
            HttpPost post = 
new 
HttpPost(dsmUrl);
            StringEntity reqEntity = 
new 
StringEntity(query);
            reqEntity.setContentType(
"application/x-www-form-urlencoded"
);
            post.setEntity(reqEntity);
            HttpResponse httpResponse = client.execute(post);            
if
(httpResponse.getStatusLine().getStatusCode() == 
200
){
                HttpEntity entity = httpResponse.getEntity();
                String message = EntityUtils.
toString
(entity, 
"utf-8"
);
//                System.out.println("結果回來了。");
//                System.out.println("action: "+action+",query: "+query+",url: "+url +",message: "+message);
                
System.
out
.println(message);
            }
//            System.out.println(arg.containsKey("Type"));
//            client = new HttpClient();
//            postMethod = new PostMethod(dsmUrl);
//            NameValuePair[] params = new NameValuePair[]{
//                    new NameValuePair("cmd",cmd),
//                    new NameValuePair("arg",arg.toJSONString())
//            };
//            postMethod.setRequestBody(params);
//            int respCode = client.executeMethod(postMethod);
//            String responseMsg = postMethod.getResponseBodyAsString().trim();
//            System.out.println(responseMsg);
        
}
catch 
(Exception e){

        }
finally 
{
//            postMethod.releaseConnection();
        
}

    }

本身保留一下java

相關文章
相關標籤/搜索