我正在尝试使用反射来获取在类中显式声明的所有公共方法(因此它c.getMethods()也不起作用,因为它也抓取了超类方法).我可以用
Method[] allMethods = c.getDeclaredMethods();
Run Code Online (Sandbox Code Playgroud)
从这个类中获取方法,但我只想使用公共方法.
此时,我正在尝试获取修改器并基于此执行某些操作,但由于某种原因,调试器中显示的修饰符值和修饰符值输出不同.例如,我有一个私有getNode方法,虽然"修饰符"值出现2在调试器中,但它会像"1"我一样输出System.out.println(c.getModifiers()).奇怪的.有另一种方法可以获得公共方法,还是我错过了一些明显的东西?谢谢你的帮助!
我正试图从谷歌的文字转语音功能中提取音频文件.基本上,你抛出链接,然后连接你想要在它结束时说出的任何内容.我已经得到以下代码,对英语工作得很好,所以我认为问题必须是如何在请求中对汉字进行编码.这是我得到的:
String text = "text to be spoken";
public static final String AUDIO_CHINESE= "http://www.translate.google.com/translate_tts?tl=zh&q=";
public static final String AUDIO_ENGLISH = "http://www.translate.google.com/translate_tts?tl=en&q=";
URL url = new URL(AUDIO_ENGLISH + text);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept-Charset", Variables.UTF_8);
if (urlConnection.getResponseCode() ==200) {
//get byte array in response
in = new DataInputStream(urlConnection.getInputStream());
} else {
in = new DataInputStream(urlConnection.getErrorStream());
}
//use commons io
byte[] bytes = IOUtils.toByteArray(in);
in.close();
urlConnection.disconnect();
return bytes;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用中文字符时,它会返回一些我无法在媒体播放器中播放的内容(我怀疑它不是一个合适的音频文件,因为绝大多数字节都是'85').所以我试过了两个
String chText = "??";
URL url = new URL(AUDIO_CHINESE + URLEncoder.encode(chText, "UTF-8)); …Run Code Online (Sandbox Code Playgroud)