編輯:關於Android編程
讀內存卡的文件
讀取圖片,視頻等媒體文件byte流,
public static byte[] readStream(String imagepath) throws Exception { FileInputStream fs = new FileInputStream(imagepath); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while (-1 != (len = fs.read(buffer))) { outStream.write(buffer, 0, len); } outStream.close(); fs.close(); return outStream.toByteArray(); }
public String readFile(String filename) { String content = null; File file = new File(filename); //for ex foo.txt try { FileReader reader = new FileReader(file); char[] chars = new char[(int) file.length()]; reader.read(chars); content = new String(chars); reader.close(); } catch (IOException e) { e.printStackTrace(); } return content; }
public void writeFile(String filePath,byte[] f){ try { FileOutputStream out = new FileOutputStream(new File(filePath)); out.write(f); out.close(); } catch (IOException e) { e.printStackTrace(); } }
public void writeFile(String filePath,String f){ FileWriter fw; try { fw = new FileWriter(filePath); fw.write(f); fw.close(); } catch (IOException e) { e.printStackTrace(); } }
如今android N都已經出來了,作為一個android開發者如果還不知道如何使用android5.X的 RecyclerView未免有點說不過去了。RecyclerV
一 IntentService介紹IntentService定義的三個基本點:是什麼?怎麼用?如何work?官方解釋如下://IntentService定義的三個基本點:
更多動態視圖MoreNewsView經常看朋友圈的動態,有的動態內容較多就只展示前面一段,如果用戶想看完整的再點擊展開,這樣整個頁面的動態列表比較均衡,不會出現個別動態占
shape和selector是Android UI設計中經常用到的,比如我們要自定義一個圓角Button,點擊Button有些效果的變化,就要用到shape和select