今天使用Android獲取網絡圖片顯示老是報一個錯!
java.net.MalformedURLException: Protocol not found
輸出之後覺得URL感覺沒有問題,可是就是無法訪問,才找到下述問題,以下內容均爲轉載自http://www.xuebuyuan.com/2056027.html:
BufferedReader.readLine()讀取第一行會出現bug,首行第一個字符會是一個空字符
BufferedReader is =new BufferedReader(new InputStreamReader(new ileInputStream(file)));
String str =is.readLine()
char c = str.charAt(0);
這時你會發現並不是你文件第一行的首個字符,而是一個空字符(不是空字符串),但讀取第二行就不會出現這問題。
解決方法:就是把第一行的第一個字符去掉。
String str =is.readLine();
char s =str.trim().charAt(0);
//65279是空字符
if(s==65279){
if(str.length()>1){
str=str.substring(1);
}
}