百度翻译api开发
来源:互联网 发布:大屏幕数据展示 html5 编辑:程序博客网 时间:2024/06/06 05:02
/** * 百度翻译() * @param from 要翻译的原语言 * @param to 翻译后的语言 * @param source 翻译的句子 * @return */public static String getResult(String from,String to,String source) throws Exception { long begintime = System.currentTimeMillis(); String returnStr = null; InputStream is = null; BufferedReader buffer = null; new String(source.getBytes(), "UTF-8"); //注意Config.BAIDU_KEY是需要去百度开发者平台申请 URL url = new URL("http://openapi.baidu.com/public/2.0/bmt/translate?client_id=" + Config.BAIDU_KEY+"&q=" + URLEncoder.encode(new String(source.getBytes(), "UTF-8")) + "&from=" + from + "&to=" + to + ""); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); urlcon.setRequestMethod("POST");//设置请求方式 urlcon.setConnectTimeout(3000); urlcon.connect(); //获取连接 is = urlcon.getInputStream(); buffer = new BufferedReader(new InputStreamReader(is)); StringBuffer bs = new StringBuffer(); String l = null; while ((l = buffer.readLine()) != null) { bs.append(l).append("/n"); } int begin = 0; int end = 0; if ((begin = bs.indexOf("dst\":\"")) != -1) { String s = bs.substring(begin+6); if ((end = s.indexOf("\"")) != -1) { returnStr = UnicodeKit.decodeUnicode(s.substring(0, end)); } } System.out.println("总共执行时间为:" + (System.currentTimeMillis() - begintime) + "毫秒"); try { if (is != null) { is.close(); } if (buffer != null) { buffer.close(); } } catch (IOException e) { e.printStackTrace(); } return returnStr; }
0 0
- 百度翻译api开发
- 基于百度翻译API开发属于自己的翻译工具
- 基于百度翻译API开发属于自己的翻译工具
- 调用百度翻译API
- 百度翻译API请求
- 百度翻译API的调用
- 百度翻译API - PHP实现
- QtQuick使用百度翻译api
- C#使用百度翻译API
- 百度翻译api 网页应用
- Android使用百度翻译api
- 百度翻译C#API接口
- c#:使用百度翻译API
- 百度翻译API(C#)
- WINFORM调用百度翻译API
- python3百度翻译API实现批量翻译
- 百度地图API开发
- 百度地图开发API
- Swap Nodes in Pairs
- Java内存模型JMM与可见性
- hadoop fsck
- DS1302 电子时钟
- UML表示接口
- 百度翻译api开发
- 数据库设计三大范式
- Oracle中的索引详解 【转】
- 《剑指Offer》面试题14:调整数组顺序使奇数位于偶数前面
- CRC算法原理及其Verilog实现
- 安卓开发性能优化
- Android SwiperRefreshLayout 首次加载显示刷新动画
- java实现矩阵快速幂算法
- 谈.Net委托与线程——创建无阻塞的异步调用(二)