我尝试读取服务器上的文本文件。但我没有返回测试。似乎我有一个异常错误。
如何在eclipse中查看错误,或显示错误?
如果我尝试记录错误,应用程序将关闭。(Log.e("Exception --->",e.getMessage());)
这里的代码在没有工作之后。
public static String getText(String urlAdress) {
String text_file = "";
BufferedReader in = null;
try {
// create a url object
URL url = new URL(urlAdress);
// create a urlconnection object
URLConnection urlConnection = url.openConnection();
// Read all the text returned by the server
in = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline
// character(s)
text_file = text_file + str;
}
in.close();
} catch (MalformedURLException e) {
text_file = "error";
Log.e("MalformedURLException --->", e.getMessage());
} catch (IOException e) {
text_file = "error";
Log.e("IOException --->", e.getMessage());
} catch (Exception e) {
text_file = "error";
// Log.e("Exception --->",e.getMessage());
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("finally IOException --->",
"Exception trying to close BufferedReader");
}
}
}
return text_file;
}
任何的想法 ?
谢谢,