首页 > 其他 > 详细

图灵机器人

时间:2017-06-10 11:41:41      阅读:291      评论:0      收藏:0      [点我收藏+]

package com.xxx.work;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Scanner;

public class Turing {
    
    /**
     * 说明:图灵机器人库从网上就可以找到
     */
    private static void testTuring(String str){
        final String key = "e7a1447ed2182d57758ca845e5a0f36e";
        String info = "";
        try {
            info = URLEncoder.encode(str, "utf-8");
            String spec = "http://www.tuling123.com/openapi/api?key="+key+"&info="+info;
            URL url = new URL(spec);
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.connect();
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
            String line = "";
            StringBuilder sb = new StringBuilder();
            if((line=br.readLine())!=null){
                sb.append(line);
            }
            br.close();
            connection.disconnect();
            System.out.println(sb);
        } catch (IOException e) {
            System.err.println("异常的信息:"+e.getMessage());
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        testTuring(str);
    }
}

图灵机器人

原文:http://www.cnblogs.com/laoxiong/p/6978117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!